-->

Saturday, February 22, 2014

Searching In Circular linked list for Data Structure in 'C'

Searching:

               In order to do searching in circular linked list, get the information to be searched and set PTR with ROOT. Compare Information with INFO of PTR, if it is equal ‘search is successful’ and terminate operation otherwise update PTR with LINK of PTR and repeat the process. Continue the operation till the end. The end is recognized by an address of first node given by ROOT stored in Link of PTR.

Algorithm for searching:

       SEARCHCLL(ROOT, IN)
       [ROOT is starting address of Linked List and
         IN is Information to search in Linked List]
        PTR<--ROOT
        If PTR = NULL Then:
         Write: ‘Empty Circular linked list’
         Exit.
        [End of If]
        Repeat While IN< >PTR-->INFO
         If PTR-->LINK = ROOT Then:
            Break
         [End of If]
         PTR<--PTR-->LINK
         [End of while]
         If PTR-->INFO = IN Then:
           Write: ‘Search Successful’
         Else:
          Write: ‘Search Unsuccessful’
         [End of If]
         Exit.

The insertion and deletion operations in circular linked list are similar to that of linear linked list and they are left as exercise. The hint is to only replace the end node checking condition of the linear linked list with that of circular linked list. This condition replacement you have learned in traversing and searching in circular linked list.

Friday, February 21, 2014

Understanding traversing in circular linked list for Data Structure in 'C


Understanding traversing in circular linked list:

Let us consider the following circular linked list.

Let us assign a pointer PTR with ROOT, address of the first node. PTR is not equal to NULL. So, the circular linked list is not empty.

Repeat while TRUE

                Write: PTR-->INFO    i.e. 6 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK     Now PTR points to second node
                Write: PTR-->INFO     i.e. 16 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK       Now PTR points to third node
                Write: PTR-->INFO        i.e.  1 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK        Now PTR points to third node
               Write: PTR-->INFO         i.e. 61 is written
               PTR-->LINK is equal to ROOT. So, break.
The infinite loop breaks. So, the traversing is complete.

C Program to create and traverse Circular linked list:

     struct node
    {
      int info; struct node*link;
    };
    typedef struct node sn;
    main( )
    {
     sn *root,*temp,*new; char choice=’y’;
     root=NULL;
     clrscr( );
     while (choice==’y’)
     {
      new=(sn*)mallloc(sizeof(sn));
      if(new==NULL)
       {
        printf(“Memory allocation error…”); exit(0);
       }
        printf(“\nEnter node information:”);
        scanf(“%d”,&new->info);
        if(root==NULL)
        {
         root=new;     temp=root;
         }
        else
        {
         temp->link=new;   temp=new;
         }
       new->link=root;
       printf(“Do you want to continue…(y/n)”);
       choice=getche( );
     } /* end of while */
     printf(“\nThe Circular Linked list is:\n\n”);
     temp=root;
     while(1)
      {
       printf(“%d”,temp->info);
       if(temp->link==root)  break;
       temp=temp->link;
      }
     }      /* end of main( )*/


How to use Editor Ajax Control in ASP.NET

Editor control is a editor or you can say modifier, as a name suggest you can format article like bold.

How to use Editor 

Step-1 : Add Script Manager Control to the design page
Step-2 : Add Editor control to the page.
Step-3 : Add one button control also handle button_click event.

Code View

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">


    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <cc1:Editor ID="Editor1" runat="server" Height="300px" Width="300px" />
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save " 
            Width="111px" />
    </p>


    </form>
</body>
</html>

Code Generate the following output

How to use Editor Ajax Control in ASP.NET

Thursday, February 20, 2014

Retrieve Record from Database using QueryString Parameter in ASP.NET

In my previous article, we already covered query string concepts. In this article, we will cover how to get record from database using query string parameter. For this types of problem, we will take two webform, first webform is used for sending querystring and pass into second web form.

Design pattern

Step-1 : Take two Web Form in solution explorer (default.aspx, default2.aspx)
Step-2 :  Bind GridView on first page (default.aspx page) using SqlDataSource control.
Step-3 : Check "select checkbox using show smart tag.
Step-4 : Handle GridView SelectedIndexChanged event , also generate QueryString in it. look like



protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("~/Default2.aspx?id=" + GridView1.SelectedRow.Cells[1].Text);
    }


Step-5 : In second page( Default2.aspx), Bind form view using SqlDataSource with Query String parameter.

Retrieve Record from Database using QueryString Parameter in ASP.NET

Retrieve Record from Database using QueryString Parameter in ASP.NET

Code view 

Default.aspx with Default.aspx.cs page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT * FROM [usertable]"></asp:SqlDataSource>
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" 
        onselectedindexchanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            <asp:BoundField DataField="address" HeaderText="address" 
                SortExpression="address" />
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>

// Code view

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("~/Default2.aspx?id=" + GridView1.SelectedRow.Cells[1].Text);
    }
}

Default2.aspx 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="id" 
            DataSourceID="SqlDataSource1" Height="174px" Width="158px">
            <EditItemTemplate>
                id:
                <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                <br />
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                id:
                <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                <br />
                name:
                <asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT * FROM [usertable] WHERE ([id] = @id)">
            <SelectParameters>
                <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Code Generate the following output

Retrieve Record from Database using QueryString Parameter in ASP.NET

Retrieve Record from Database using QueryString Parameter in ASP.NET

Traversing in Circular Linked List for Data Structure in'C'

Traversing in Circular Linked List:

     To visit all the nodes of a circular linked list, start from the ROOT and visit first element. Then with the help  of link field visit the second element, similarly visit all the elements. The last node is recognized by the
ROOT address in its link field. So, set a pointer variable PTR with ROOT. Process PTR-->INFO and update PTR by LINK of PTR i.e. PTR<--PTR-->LINK. Repeat till the PTR-->LINK is equal to ROOT.

The algorithm is as follows:

       TRAVERSCLL (ROOT)
       PTR<--ROOT
       If PTR = NULL Then:
          Write: ‘Empty Circular linked list’; Exit.
       [End of If]
       Repeat While TRUE
         Apply process to PTR-->INFO
         If PTR-->LINK = ROOT Then:
           Break.      [To break the infinite loop]
         [End of If]
         PTR<--PTR-->LINK
       [End of while]
       Exit.

Algorithm to print the contents of a linked list:

       TRAVERELL (ROOT)
       PTR<--ROOT
       If PTR = NULL Then:
         Write: ‘Empty Circular linked list’;  Exit.
      [End of If]
      Repeat While TRUE                     [infinite loop]
        Write: PTR-->INFO
        If PTR-->LINK = ROOT Then:
          Break.                       [To break the infinite loop]
        [End of If]
        PTR<--PTR-->LINK
      [End of while]
      Exit.

Wednesday, February 19, 2014

How to Manage Database with Creating and Storing information in SQL

As a database developer, programmer might need to create databases to store information. At times, you might also delete a database, if it is not required. Therefore, it is essential to know how to create and delete a database.
The SQL Server contains some standard system databases. Before creating a database, it is important to identify the system databases supported by SQL Server and their importance.

System databases are the standard databases that exist in every instance of SQL Server. These databases contain a specific set of tables that are used to store server-specific configurations, templates for other databases. In addition, these databases contain a temporary storage area required to query the database.

SQL Server contains the following system databases:

master Database

The master database records all the server-specific configuration information, including authoried users, databases, system configuration settings, and remote servers. In addition, it records the instance-wide metadata, such as logon accounts, endpoints, and system configuration settings.

The master database contains critical data that controls the SQL Server operations. It is advisable not to give any permission to users on the master database. It is also important to update the backups of the master database to reflect the changes that take place in the database as the master database records the existence of all other databases and the location of those database files.

The master database also stores the initialization information of the SQL Server. Therefore if the master database is unavailable, the SQL Server database engine will not be started.

tempdb database

The tempdb database is a temporary database that holds all temporary tables and sor procedures. It is automatically used by the server to resolve large or nested queries or to sort data before displaying the results to the user.
All the temporary tables and results generated by the GROOUP BY, ORDER BY, and DISTINCT clauses are stored in the tempdb database. You should not save any database object in the tempdb database because this database is recreated every times the SQL Server starts. This results in loosing data you saved earlier.

model database

The model database acts as a template or a prototype for the new databases. Whenever a database is created, the contents of the model database are copied to the new database.
In this database, you can set the default values for the various arguments to be specified in the Data Definition Language (DDL) statements to create database objects. In addition, if you want every new database to contain a particular database object, you can add the object to the model database. After this, whenever you create a new database the object will also be added to the database.

msdb Database

The msdb database supports the SQL Server Agent. The SQL Server Agent is a tool that schedules periodic activities of the SQL Server, such as backup and database mailing. The msdb database contains task scheduling, exception handling, alert management, and system operator information needed for the SQL Executive Service. The msdb database contains a few system-defined tables that are specific to the database.
As a database developer, you can query this database to retrieve information on alerts, exceptions, and schedules. For example, you can query this database to know the schedule for the next backup and to know the history of previously scheduled backups. You can also query this database to know how many database e-mail messages have been sent to the administrator. However, there are tools available to perform these database administration tasks.

resource Database

The Resource database is a read-only database that contains all the system objects, such as system-defined procedures and view that are included with SQL Server. The Resource database does not contain user data or user metadata.

Types and Examples of Binary Operators in Java Programming part-2

Operators that act upon two operands are referred to as Binary Operators. The operands of a binary operator are distinguished as the left or right operand. Together, the operator and its operands constitute an expression.

Addition operator (+). The arithmetic binary operator ads the values of its operands and the result is the sum of the values of its operands and the result is the sum of the values of its two operands. For example,
4 + 20 result in 24.
A + 5 (where a = 2) result in 7.
A + b (where a = 4, b = 6) result in 10.
Its operands may be of integer (byte, short, char, int, long) or float (float, double) types.

Subtraction operator (-). The – operator subtracts the second operand from the first. For example,
14 – 3 evaluates to 11
A – b (where a = 7,  b = 5) evaluates to 2.
The operands may be of integer or float types.

Multiplication operator (*). The * operator multiplies the values of its operands. For example,
3 * 4 evaluates to 12.
b * 4 (where b = 6) evaluates to 24.
a * c (where a = 3, c = 5) evaluates to 15.
The operands may be of integer or float types.

Division operator (/). The / operator divides its first operand by the second. For example,
100 / 5 evaluates to 20.
a / 2 (a = 16) evaluates to 8.
a / b (a =15.9, b = 3) evaluates to 5.3.
The operands may be of integer or float types.

Modulus operator (%). The % operator finds the modulus of its first operand relative to the second. That is, it produces the remainder of dividing the first by the second operand. For example,

19 % 6 evaluates to 1, since 6 goes into 19 three times with a reminder 1. Similarly 7.6 % 2.9 results into 1.8 and – 5% -2 result into -1.

© Copyright 2013 Computer Programming | All Right Reserved