-->

Thursday, February 20, 2014

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.

Understanding creation of circular linked list For Data Structure in 'C'

Understanding creation of circular linked list

Initially,







One node with information ‘6’ is added to the circular linked list. Then the list becomes,


Another node with information ‘16’ is added to the circular linked list. Then the list become,


Similarly when two more nodes are added with information ‘1’ and ‘61’, the list become,



Traversing in circular Linked List:
   
           To visit all the node 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.
Algorithm is as follows:

        TRAVERSECLL (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:

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


Tuesday, February 18, 2014

Circular Linked List for Data Structure in C Programming

Circular Linked List

A little variation applied to linear linked list gives another type of linked list called as circular linked list. You might have observed in the linear linked list that the last node always points to the invalid address such as NULL address. Practically speaking the memory is wasted. Instead of NULL address if we think to keep the valid address in that field such as the address of the first node available in external pointer ROOT, then the linear linked list becomes circular linked list. As the last point in the circular linked list always points to the first node this type of linked list carries the name circular. The implementation is straightforward.
Whenever you create the circular linked list always assign the pointer field of the newly added node with the first node address given by ROOT(external pointer).

Algorithm to create a circular linked list:
         CREATECLL
         ROOT<--NULL;       CHOICE<--‘Y’
         Repeat While CHOICE=’Y’
            If AVAIL=NULL Then:
               Write: ’Memory Allocation Error’
               Exit.
            Else:
              NEW<--AVAIL
              NEW-->INFO<--Information
              AVAIL<--AVAIL-->LINK
           [End of if]
           If ROOT=NULL Then:
             ROOT<--NEW;   TEMP<--NEW
           Else:
             TEMP-->LINK<--NEW;    TEMP<--NEW
           [End of If]
           NEW-->LINK<--ROOT
           Write: ‘Do you want to add another node?(Y/N)’
           Read: CHOICE
          [End of while]
        Exit.

How to use Correlated Subqueries in SQL Programming

In SQL programming, a correlated subquery can be defined as a query that depends on the outer query for its evaluation. In a correlated subquery, the WHERE clause references a table in the FROM clause. This means that the inner query is evaluated for each row of the table specified in the outer query.

For example, the following query displays the employee ID, designation, and number of hours spent on vacation for all the employees whose vacation hours are greater than the average vacation hours identified for their title:

SELECT BusinessEntityID, JobTitle, VacationHours
FROM HumanREsources.Employee el WHERE el.VacationHours>
(SELECT AVG(e2.VacationHours)
FROM HumanResources.Employee e2 WHERE el.JobTitle = e2.JobTitle)

In the preceding example, the inner query returns the Titles of the employees, from the Employee table, whose vacation hours are equal to the average vacation hours of all employees. The outer query retrieves the Employee ID, Title, and VacationHours of all the employees whose vacation hours is greater than the average vacation hours retrieved by the inner query. The output of the correlated subquery is shown in the following figure.

How to use Correlated Subqueries in SQL Programming

Custom Login control with session and cookies in ASP.NET

Introduction

Cookies is a Text file , which is sent by web server and saved on client machine. As Well as Session saved on server machine. Here we take a simple example, first we will create a sessionId, After that saved it into cookies.

Designing pattern 

Step-1 : Create Database table with some column , these are

sno  int  primary_key column with automatic increment
username  nvarchar(50)
password nvarchar(50)
userID  nvarchar(max)

Step-2 : Fill this table with some data.
Step-3 : Design Login Control with proper validation, look like
Design Login Control with proper validation

Code View

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;


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

        if (Request.Cookies["mycookie"]!= null)
        {
            Response.Redirect("~/welcome.aspx");

        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = true;

        SqlConnection con = new SqlConnection();
                con.ConnectionString =ConfigurationManager .ConnectionStrings ["ConnectionString"].ToString ();
        con.Open ();
        SqlCommand cmd=new SqlCommand ();
        cmd.CommandText ="select * from usertable";
        cmd.Connection =con;
        SqlDataReader rd=cmd.ExecuteReader ();
        while (rd.Read ())
{
        if (TextBox1 .Text ==rd["username"].ToString () && TextBox2 .Text ==rd["password"].ToString ())
{
        Session["userID"] = rd["userID"].ToString ();
        flag = false;
        break;

}
}
        if (flag == false)
        {
            if (CheckBox1.Checked)
            {
                HttpCookie mycookie = new HttpCookie("mycookie");

                Response.Cookies["mycookie"]["userID"] = Session["userID"].ToString();
                Response.Redirect("~/welcome.aspx");
               

            }
            else
            {
                Response.Redirect("~/welcome.aspx");

            }


        }
        else
        {
            Label1.Text = "username and password wrong";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        
    }
}

Code generate the following output

Custom Login control with session and cookies in ASP.NET

Custom Login control with session and cookies in ASP.NET

First check cookies on page_load method, if exists in browser, directly you can navigate to welcome page. If doesn't then you will interface with login page. Create session and save into cookies after select checkbox.

© Copyright 2013 Computer Programming | All Right Reserved