Monday, 22 July 2013

How to be a good Programmer?

This is the question you always want to answer to someone but you didn't get it yet yourself. First I clear one thing that i am not a good programmer and not the writer at all but i can say i am still learning. Yes I am better than quite a few people when it comes to programming, but that's merely because they are lazy and like to sit on idly all day and never bother about programming. Their horrible skills make my less horrible skills look marvelous.
Things that's help you to be a good programmer mention below  they are what I have wanted to be and I am not. So lets dive in.
1.Decide why you want to become a good programmer
this is the main question you have to ask yourself  Is it because you want a job, preferably in a high paying software firm? Great. Then you are set to reach NOWHERE. All good programmers I know are good because they loved what they did.
2. Programming languages
Very often people equate good coding skills with number of programming langauges known. Thats just damn untrue. While knowing a lot of programming language is good and sometimes, even, essential; it is more important that you know one or two languages very well.
 3. Algorithms
Any good programmer has a good understanding of algorithms. Its not necessary that you know each algorithm by heart (in fact good programmers never learn things by rote) but you must understand when to use what. Algorithms will broaden your understanding and give you new ways to tackle problems. Another important thing is Data Structures. Its more important than algorithm.
4. Coding contests
 Coding contests are good for developing your algorithmic skills and they make you think fast.
5. Design Patterns    
 Any art is learn t by emulating. And therefore, you must emulate the best. Design Patterns are tried and tested architectural (of the software kind) solutions to some commonly encountered software design issues.

Friday, 5 July 2013

THIS PROGRAM SEARCHS AN ITEM FROM SIMPLE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list start, *prev, *new1;

void search(struct list *);
void create_list(struct list *);
void display(struct list *);

 /* Function to create linked list */

 void create_list(struct list *ptr)
{
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Searching a value */

void search(struct list *ptr)
{
    int i = 1;
    int item;
    ptr = &start;
    prev = &start;
    printf("\n\n ------------------------------------");
    printf("\n Enter the item you want to search:");
    scanf("%d", &item);
    ptr = ptr->link;
    prev= prev->link;


    while(ptr)
    {
        if( item == ptr->info )
        {
            printf("\n\n ===============================");
            printf("\n Item is found at location: %d",i);
            printf("\n ===============================");
            break;
        }
        else
        {
            ptr = ptr->link;
            prev= prev->link;
        }
        i++;
    }
    if(item != ptr->info)
        printf("\n\n ====================");
        printf("\n Item does not exist");
        printf("\n ====================");
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *)malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n\n ---------------");
    printf("\n Linked list is:");
    printf("\n ---------------");
    display(ptr);
    search(ptr);
    getch();
}

THIS PROGRAM INSERTS A NODE AT THE END OF SIMPLE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list start, *prev, *new1;

void insert_last(struct list *);
void create_list(struct list *);
void display(struct list *);

 /* Function to create linked list */

 void create_list(struct list *ptr)
{
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to insert node at the end */
void insert_last(struct list *ptr)
{
    ptr = start.link;
    prev = &start;

    while(ptr)
    {
        ptr = ptr->link;
        prev= prev->link;
    }
    if(ptr == NULL)
    {
        new1 = (struct list* ) malloc(sizeof(struct list));
        new1->link = ptr ;
        prev->link = new1;
        printf("\n\n ------------------------------------");
        printf("\n Enter the item you want to insert: ");
        scanf("%d",&new1->info);
    }
}
 /* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    insert_last(ptr);
    printf("\n ------------------------------------------\n");
    printf("\n Linked list after insertion of last node: \n");
    printf("\n ------------------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM INSERTS A NODE AT THE BEGINNING OF SIMPLE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list start, *prev, *new1;

void insert_first(struct list *);
void create_list(struct list *);
void display(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to insert node at beginning */

void insert_first(struct list *ptr)
{
    ptr = start.link;
    prev = &start;
    new1 = (struct list* ) malloc(sizeof(struct list));
    new1->link = ptr ;
    prev->link = new1;
    printf("\n\n --------------------------------------");
    printf("\n Enter the item you want to insert: ");
    scanf("%d",&new1->info);

}

/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    insert_first (ptr);
    printf("\n ------------------------------------------\n");
    printf("\n Linked list after insertion of first node: \n");
    printf("\n ------------------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM DELETES LAST NODE FROM SIMPLE LINKED LIST


#include<stdio.h>
#include<malloc.h>

struct list
{
    char info;
    struct list *link;
};

int i;
int num ;
struct list start, *prev;

void del_last(struct list *);
void display(struct list *);
void create_list(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
{
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Function to delete last node */

void del_last(struct list *ptr)
{

    ptr = start.link;
    prev = &start;

    if (ptr == NULL)
    {
        printf("\n\n\n ---------");
        printf("\n Underflow");
        printf("\n ---------");
    }

    else

        while(ptr->link)
        {
            ptr = ptr->link;
            prev = prev->link;
        }

        prev->link = ptr->link;
        free(ptr);


}
/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ---------------\n");
    display(ptr);
    del_last(ptr);
    printf("\n ---------------------------------------------\n");
    printf("\n Linked list after deletion of last node: \n");
    printf("\n ---------------------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM DELETES FIRST NODE FROM SIMPLE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;

};

int i;
struct list start, *prev;
void create_list(struct list *);
void display(struct list *);
void del_first(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to delete first node */

void del_first(struct list *ptr)
{
    ptr = start.link;
    prev = &start;

    prev->link = ptr->link;
    free(ptr);

}


/* Function to show list */

void display(struct list *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %d", ptr->info);
            ptr = ptr->link;
        }
}


/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Doubly linked list is: ");
    printf("\n ----------------------\n");
    display(ptr);
    del_first (ptr);
    printf("\n ------------------------------------------------\n");
    printf("\n Doubly linked list after deletion of first node: \n");
    printf("\n ------------------------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM CREATES A HEADER LINKED LIST




#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list *start, *new1;

void insert(struct list *);
void create_hlist(struct list *);
void display (struct list *);

/* Function to create a header linked list */

void create_hlist(struct list *ptr)
{
    int n;

    start->link = NULL;  /* Empty list1 */

    ptr = start;      /* Point to the header ptr of the list1 */
    ptr->link = (struct list* ) malloc(sizeof(struct list)); /* Create header ptr */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list* ) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Input the ptr: %d: ", i+1);
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n -----------------");
    printf("\n Total nodes = %d", i);
    printf("\n -----------------\n");
    ptr = start;
    ptr->info = i;
}

/* Function to insert a node */

void insert(struct list *ptr)
{
    int loc,num = 1;
    int count;
    ptr = ptr->link;
    count = ptr->info;
    ptr = start;
    printf("\n -----------------------------------------------\n");
    printf("\n Enter the loc where you want to insert node: ");
    scanf("%d",&loc);
    while(count)
    {
        if((num) == loc)
        {
            new1 = (struct list* ) malloc(sizeof(struct list));
            new1->link = ptr->link ;
            ptr->link = new1;
            printf("\n -----------------------------------------------\n");
            printf("\n Enter the item you want to insert: ");
            scanf("%d", &new1->info);
            ptr = ptr->link;
        }
        else
        {
            ptr = ptr->link;
            count--;
        }
        num++;
    }
    ptr = start;
    ptr->info = ptr->info+1;
}

/* Function to diplay  header linked list */

void display(struct list *ptr)
{
    int count;
    ptr = start;
    count = ptr->info;
    ptr = ptr->link;
    while (count)
    {

        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
        count--;
    }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_hlist (ptr);
    printf("\n\n ----------------------");
    printf("\n Header linked list is:");
    printf("\n ----------------------\n");
    display (ptr);
    insert(ptr);
    printf("\n\n\n -----------------------------------");
    printf("\n Header linked list after insertion:");
    printf("\n -----------------------------------\n");
    display (ptr);
    getch();
}

THIS PRORAM PERFORMS INSERTOIN AT THE END OF DOUBLY LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct dlist
{
    char info[20];
    struct dlist *link;
    struct dlist *prev;
};
int i;
struct dlist  start, *new1;
void insert_last (struct dlist *);
void create_dlist (struct dlist *);
void display (struct dlist *);

/* Function to create doubly linked list */

 void create_dlist(struct dlist *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n\n\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter string values in nodes\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%s", ptr->info);
        ptr->link = NULL;
        fflush(stdin);
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}

/* Function to insert node at end */

void insert_last (struct dlist *ptr)
{
    ptr = start.link;

    new1 = (struct dlist *) malloc(sizeof(struct dlist ));
    printf("\n\n --------------------------------------");
    printf("\n Enter the item you want to insert: ");
    scanf("%s",new1->info);

    while(ptr->link)
    {
          ptr = ptr->link;
    }


    new1->link = NULL;
    new1->prev = ptr;
    ptr->link = new1;
}

/* Function to display the list */

void display(struct dlist *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %s", ptr->info);
            ptr = ptr->link;
        }
}

/* Main Function */

void main()
{
    struct  dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist(ptr);
    printf("\n ----------------------");
    printf("\n Doubly linked list is:\n");
    printf("\n ----------------------");
    display(ptr);
    insert_last (ptr);
    printf("\n\n\n ----------------------------------------------");
    printf("\n Doubly linked list after insertion at the end: \n");
    printf("\n ----------------------------------------------");
    display(ptr);
    getch();
}


THIS PROGRAM DELETES THE LAST NODE FROM DOUBLY LINKED LIST




#include<stdio.h>
#include<malloc.h>

struct dlist
{
    int info;
    struct dlist *link;
    struct dlist *prev;
};

int i ;
struct dlist start, *prev;

void del_last (struct dlist *);
void create_dlist (struct dlist *);
void display (struct dlist *);



 /* Function to  create doubly linked list */
void create_dlist(struct dlist *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in nodes\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        fflush(stdin);
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}

   /* Function to delete last node */

void del_last(struct dlist *ptr)
{

    ptr = start.link;
    prev = &start;

    if (ptr == NULL)
    {
        printf("\n\n\n ----------");
        printf("\n Underflow");
        printf("\n ----------");
    }

    else

        while(ptr->link)
        {
            ptr = ptr->link;
            prev = prev->link;
        }

        prev->link = ptr->link;
        free(ptr);


}

/* Function to display the list */

void display(struct dlist *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t%d", ptr->info);
            ptr = ptr->link;
        }
}

/* Main Function */

void main()
{
    struct dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist (ptr);
    printf("\n Doubly linked list is:\n");
    printf("\n ----------------------");
    display(ptr);
    del_last(ptr);
    printf("\n\n -----------------------------------------------");
    printf("\n Doubly linked list after deletion of last node:");
    printf("\n -----------------------------------------------");
    display(ptr);
    getch();
}

THIS PROGRAM DELETES A NODE FROM GIVEN LOCATION OF DOUBLY LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct dlist
{
    int info;
    struct dlist *link;
    struct dlist *prev;
};

int i ;
struct dlist start;

void del_node (struct dlist *);
void create_dlist (struct dlist *);
void display (struct dlist *);

/* Function to  create doubly linked list */

void create_dlist(struct dlist *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}

/* Function to delete a node  */

void del_node (struct dlist *ptr)
{
    int loc;
    int count = 0;
    printf("\n\n\n ---------------------------------------");
    printf("\n Enter the location you want to delete: ");
    scanf("%d", &loc);

    ptr = start.link;
    if ( ptr == NULL)
    {       printf("\n\n======================");
        printf("\n Underflow\n");
        printf("\n List is empty\n");
        printf("====================\n");
    }
    else

        while(ptr)
        {
            if((count + 1) == loc)
            {
                ptr->prev->link = ptr->link ;
                ptr->link->prev = ptr->prev ;
                free(ptr);
            }
            else
            {
                ptr = ptr->link;

            }
            count++;
        }

}

/* Function to display the list */

void display(struct dlist *ptr)
{
    ptr = start.link;

    while (ptr)
    {

        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Main Function */

void main()
{
    struct dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist(ptr);
    printf("\n\n ----------------------");
    printf("\n Doubly linked list is: ");
    printf("\n ----------------------");
    display(ptr);
    del_node(ptr);
    printf("\n\n\n ----------------------------------");
    printf("\n Doubly linked list after deletion: ");
    printf("\n ----------------------------------");
    display(ptr);
    getch();
}

THIS PROGRAM CREATES A SIMPLE LINKED LIST




#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
struct list start;

void create_list(struct list *);
void display(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
{
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *)malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n\n ---------------");
    printf("\n Linked list is:");
    printf("\n ---------------");
    display(ptr);
    getch();
}


THIS PROGRAM INSERTS A NODE AT GIVEN LOCATION IN SIMPLE LINKED LIST




#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list start, *prev, *new1;

void insert_node(struct list *);
void create_list(struct list *);
void display(struct list *);

 /* Function to create linked list */

 void create_list(struct list *ptr)
 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}


/* Function to insert node at given locatoin */

void insert_node(struct list *ptr)
{
    int loc;
    int i=0;
    ptr = start.link;
    prev = &start;
    printf("\n\n ----------------------------------------------------");
    printf("\n Enter the location where you want to insert node:");
    scanf("%d",&loc);

    while(ptr)
    {
        if((i+1) == loc)
        {

            new1 = (struct list *) malloc(sizeof(struct list));
            new1->link = ptr ;
            prev->link = new1;
            printf("\n Enter the item you want to insert: ");
            scanf("%d",&new1->info);
            break ;
        }
        else
        {
            ptr = ptr->link;
            prev= prev->link;
        }
        i++;
    }
}

/* Main Function */

void main()
{
    struct  list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n ----------------------");
    printf("\n Linked list is:\n");
    printf("\n ----------------------");
    display(ptr);
    insert_node(ptr);
    printf("\n\n\n ----------------------------");
    printf("\n Linked list after insertion: \n");
    printf("\n ----------------------------");
    display(ptr);
    getch();
}




THIS PROGRAM INSERTS AN ITEM INTO SORTED LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num;
struct list start, *prev, *new1;

void insert_node(struct list *);
void create_list(struct list *);
void display(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node in ASCENDING ORDER\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}


/* Function to insert an item */
void insert_node(struct list *ptr)
{

    int item;

    ptr = start.link;
    prev = &start;
    printf("\n\n --------------------------------------");
    printf("\n Enter the item you want to insert:");
    scanf("%d",&item);

    while((item > (ptr->info)) && (ptr!=NULL))
    {
        prev=ptr;
        ptr= ptr->link;
    }

        new1 = (struct list *) malloc(sizeof(struct list));
        new1->link = ptr;
        prev->link = new1;
        new1->info = item;
}

/* Main Function */

void main()
{
    struct  list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n ----------------------");
    printf("\n Linked list is:\n");
    printf("\n ----------------------");
    display(ptr);
    insert_node(ptr);
    printf("\n\n\n ----------------------------");
    printf("\n Linked list after insertion: \n");
    printf("\n ----------------------------");
    display(ptr);
    getch();
}


THIS PROGRAM DELETES A NODE AT GIVEN LOCATION FROM SIMPLE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num ;
struct list start, *prev;
void  del_node(struct list *);
void  create_list(struct list *);
void display(struct list *);

/* Function to create linked list */

 void create_list(struct list *ptr)
 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to display the list */

void  display(struct list *ptr)
{
    ptr = start.link;
    while (ptr)
    {
        printf("\n\n\t\t%d", ptr->info);
        ptr = ptr->link;
    }
}
/* Function to delete node from given location */

void del_node(struct list *ptr)
{
    int i= 1;
    int loc;
    ptr = start.link;
    prev = &start;

    printf("\n\n\n Enter the location of node you want to delete:");
    scanf(" %d", &loc);

    while(ptr)
    {
        if(i == loc)
        {
            prev->link = ptr->link;
            free(ptr);
            break ;
        }
        else
        {
            ptr = ptr->link;
            prev = prev->link;
        }
        i++;
    }

}

/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ---------------\n");
    display(ptr);
    del_node(ptr);
    printf("\n ---------------------------------------------\n");
    printf("\n Linked list after deletion of last node: \n");
    printf("\n ---------------------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM DELETES AN ITEM FROM SIMPLE LINKED LIST


#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int num ;
struct list start, *prev;
void del_node(struct list *);
void  create_list(struct list *);
void display(struct list *);

/* Function to create linked list */

void create_list(struct list *ptr)

 {
    int n;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    i=0;
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n ---------------");
    printf("\n Total nodes = %d",i);
    printf("\n ---------------\n\n");
}

/* Function to delete a node*/

void del_node(struct list *ptr)
{
    int loc = 1;
    int item;

    ptr = start.link;
    prev = &start;

    printf("\n\n\n ------------------------------------");
    printf("\n Enter the item you want to delete: ");
    scanf("%d", &item);

    while(ptr)
    {
        if(ptr->info == item)
        {
            printf("\n Location of the item in the list is : %d", loc);
            prev->link = ptr->link;

            free(ptr);
            break ;
        }
        else
        {
            ptr = ptr->link;
            prev = prev->link;
        }
        loc++;
    }

}

/* Function to display list */

void display(struct list *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %d", ptr->info);
            ptr = ptr->link;
        }
}


/* Main Function */

void main()
{

    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list(ptr);
    printf("\n Linked list is: ");
    printf("\n ---------------\n");
    display(ptr);
    del_node(ptr);
    printf("\n ---------------------------------\n");
    printf("\n Linked list after deletion: \n");
    printf("\n ---------------------------------\n");
    display(ptr);
    getch();

}

THIS PROGRAM CREATES STRING TYPE LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    char info[20];
    struct list *link;
    struct list *prev;
};

int i ;
struct list start;

void create_list (struct list *);
void display (struct list *);

 /* Function to create linked list */

 void create_list(struct list *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n\n\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter string values in nodes\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct list *) malloc(sizeof(struct list));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%s", ptr->info);
        ptr->link = NULL;
        fflush(stdin);
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}

/* Function to display the list */

void display(struct list *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %s", ptr->info);
            ptr = ptr->link;
        }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *) malloc(sizeof(struct list));
    clrscr();
    create_list (ptr);
    printf("\n Linked list is: ");
    printf("\n ----------------\n");
    display (ptr);
    getch();
}










THIS PROGRAM PERFORMS INSERTION AT THE BEGINNING OF DOUBLY LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct dlist
{
    char info[20];
    struct dlist *link;
    struct dlist *prev;
};

int i;
struct dlist  start, *new1;
void insert_first (struct dlist *);
void create_dlist (struct dlist *);
void display (struct dlist *);

/* Function to create doubly linked list */
void create_dlist(struct dlist *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n\n\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter string values in nodes\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%s", ptr->info);
        ptr->link = NULL;
        fflush(stdin);
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}

/* Fuction to insert node at beginning */

void insert_first (struct dlist *ptr)
{
    ptr = start.link;

    new1 = (struct dlist *) malloc(sizeof(struct dlist ));

    printf("\n\n ---------------------------------------");
    printf("\n Enter the item you want to insert: ");
    gets(new1->info);
    new1->link = ptr;
    new1->prev = ptr->prev;
    ptr->prev->link = new1;
    ptr->prev = new1;

}

void display(struct dlist *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %s", ptr->info);
            ptr = ptr->link;
        }
}

/* Main Function */

void main()
{
    struct dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist (ptr);
    printf("\n\n ----------------------");
    printf("\n Doudly linked list is:");
    printf("\n ----------------------\n");
    display(ptr);
    insert_first (ptr);
    printf("\n\n\n -------------------------------------------------");
    printf("\n Doudly linked list after insertion at beginning:");
    printf("\n -------------------------------------------------");
    display (ptr);
getch();
}



THIS PROGRAM DELETES FIRST NODE OF DOUBLY LINKED LIST




#include<stdio.h>
#include<malloc.h>

struct dlist
{
    char info[20];
    struct dlist *link;
    struct dlist *prev;
};

int i ;
struct dlist start;

void del_first (struct dlist *);
void create_dlist (struct dlist *);
void display (struct dlist *);

 /* Function to create doubly linked list */

 void create_dlist(struct dlist *ptr)
{
    int n;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n\n\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n ==============================================================================\n");
    printf("\n Note That:\n -----------\n Enter string values in nodes\n");
    printf("\n ==============================================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%s", ptr->info);
        ptr->link = NULL;
        i++;
    }
    printf("\n\n --------------------");
    printf("\n Total nodes = %d",i);
    printf("\n --------------------\n\n");
}
/* Function to delete first node */

void del_first (struct dlist *ptr)
{
    ptr = start.link;

    ptr->prev->link = ptr->link ;
    ptr->link->prev = ptr->prev ;
    free(ptr);

}

/* Function to display the list */

void display(struct dlist *ptr)
{
    ptr = start.link;

        while (ptr)
        {

            printf("\n\n\t\t %s", ptr->info);
            ptr = ptr->link;
        }
}

/* Main Function */

void main()
{
    struct dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist (ptr);
    printf("\n Doubly linked list is: ");
    printf("\n ----------------------\n");
    display (ptr);
    del_first (ptr);
    printf("\n ------------------------------------------------\n");
    printf("\n Doubly linked list after deletion of first node: \n");
    printf("\n ------------------------------------------------\n");
    display(ptr);
    getch();
}

WRITE A PROGRAM TO CREATES CIRCULAR HEADER LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int number;
struct list *start, *new1;
void create_list(struct list *);
void display(struct list *);


/* Function to create a circular header linked list */

void create_list( struct list *ptr)
{
    int n;

    ptr = start;      /*ptr points to the header node */
    ptr->link = (struct list *) malloc(sizeof(struct list));
    i = 0;
    printf("\n\n\n how many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n =======================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n =======================================================\n");
    while(i!=n)
    {
        ptr->link = (struct list* ) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the node %d:", (i+1));
        scanf("%d", &ptr->info);
        i++;
    }
    printf("\n\n\n------------------------\n");
    printf("\n Total nodes = %d", i);
    printf("\n\n________________________\n");
    ptr = start;
    ptr->info = i; /* Header node holds information about total nodes in list */
}



/* Function to display the list */

void display(struct list *ptr)
{
    int count;
    ptr = start;
    count = ptr->info;
    ptr = ptr->link;

    while (count>0)
    {

           printf("\n\t\t %d \n",ptr->info);
           ptr = ptr->link;
        count=count-1;
    }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *) malloc(sizeof(struct list));
      clrscr();
    create_list(ptr);
    printf("\n------------------------\n");
    printf("\n Circular linked list :\n");
    printf("\n------------------------\n");
    display(ptr);
    getch();
}

WRITE A PROGRAM TO CREATES A SIMPLE DOUBLY LINKED LIST


#include<stdio.h>
#include<malloc.h>

struct dlist
{
    int info;
    struct dlist *link;
    struct dlist *prev;
};

int num ;
struct dlist start;
void create_dlist (struct dlist *);
void display (struct dlist *);

/* Function to creates doubly linked list */

void create_dlist(struct dlist *ptr)
{
    int n,i=0;
    start.link = NULL;  /* Empty list */
    start.prev = NULL;
    ptr = &start;      /* Ptr points to the start pointer */
    printf("\n How many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n =======================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n =======================================================\n");
    while( i!=n)
    {
        ptr->link = (struct dlist *) malloc(sizeof(struct dlist));
        ptr->link->prev = ptr;
        ptr = ptr->link;
        printf("\n Enter the values of the node : %d: ", (i+1));
        scanf("%d", &ptr->info);
        ptr->link = NULL;
        fflush(stdin);
        i++;
    }
    printf("\n\n--------------------");
    printf("\n Total nodes = %d",i);

}

/* Function to display the list */

void display (struct dlist *ptr)
{
    ptr = start.link;
    printf("\n\n\t\t-----------------");
    printf("\n\t\tForwad Traversal:\n\t\t-----------------\n\n");
    while (ptr->link)
    {

        printf("\n\n\t\t  %d", ptr->info);
        ptr = ptr->link;
    }
    printf("\n\n\t\t  %d", ptr->info);

    printf("\n\n\t\t-------------------");
    printf("\n\t\tBackward Traversal:\n\t\t-------------------\n\n");
    do {

        printf("\n\n\t\t  %d", ptr->info);
        ptr = ptr->prev;
    } while (ptr->prev);
}

void main()
{
    struct dlist *ptr = (struct dlist *) malloc(sizeof(struct dlist));
    clrscr();
    create_dlist(ptr);
    printf("\n\n--------------------");
    printf("\n\n\n Doubly linked list is: \n");
    printf("\n========================");
    display(ptr);
    getch();
}


Program to Print elements of linear array.



//Header Files
#include<stdio.h>
#include<conio.h>
int arr[10],n,j;
void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);
printf("\n Enter array elements....");
for(int i=0;i<=n-1;i++)
    scanf("%d",&arr[i]);
printf("\n Printing of Elements...");
j=0;

while(j<=n-1)
{
    printf("\n");
    printf("%d", arr[j]);
    j=j+1;
}

getch();
}

Program to delete an element from the array



//Header Files
#include<stdio.h>
#include<conio.h>
#include<process.h>

int arr[10],n,i,j,k,item,loc;
void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);

if(n>10)
{
    printf("Entered value exceed the limit of array");
    getch();
    exit(0);
}

printf("\n Enter array elements....");
for(i=0;i<=n-1;i++)
    scanf("%d",&arr[i]);

printf("Enter the location of the element to be deleted...");
scanf("%d",&loc);
item=arr[loc];
for(j=loc;j<=n-2;j++)
    arr[j]=arr[j+1];

printf("\n Array after Deletion...");
k=0;

while(k<=n-2)
{
    printf("\n");
    printf("%d", arr[k]);
    k=k+1;
}
getch();
}

Program to insert an element in an array



//Header Files
#include<stdio.h>
#include<conio.h>
#include<process.h>
int arr[10],n,i,j,k,item,loc;

void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);

if(n>10)
{
    printf("Entered value exceed the limit of array");
    getch();
    exit(0);
}
printf("\n Enter array elements....");
for(i=0;i<=n-1;i++)
    scanf("%d",&arr[i]);
printf("Enter the element to be inserted...");
scanf("%d",&item);
printf("Enter its location...");
scanf("%d",&loc);
for(j=n-1;j>=loc;j--)
    arr[j+1]=arr[j];

arr[loc]=item;
printf("\n Array after Insertion...");
k=0;
while(k<=n)
{
    printf("\n");
    printf("%d", arr[k]);
    k=k+1;
}
getch();
}

Program to Sort(in ascending order) set of numbers using BUBBLE SORT

#include<stdio.h>
#include<conio.h>
#include<process.h>
#define true 1
#define false 0
int arr[10],n,i,j,temp;

void main()
{
clrscr();
printf("Enter size of array:");
scanf("%d", &n);
if(n>10)
{
    printf("Entered value exceed the limit of array");
    getch();
    exit(0);
}
printf("\n Enter array elements....");
for(i=0;i<=n-1;i++)
    scanf("%d",&arr[i]);

//LOGIC of BUBBLE SORT
for(i=0;i<n-1;i++)
{
    for(j=0;j<(n-1)-i;j++)
    {
        if(arr[j]>arr[j+1])
        {
            temp=arr[j];
            arr[j]=arr[j+1];
            arr[j+1]=temp;
        }
    }
}

printf("\n Sorted Array....");
for(i=0;i<=n-1;i++)
    printf("\n%d",arr[i]);

getch();
}

Write a program to two show Factorial of a number

#include<iostream.h>
int rec(int);
main()
{
    int a ,fact;
    cout<<"enter any number";
    cin>>a;
    fact=rec(a);
    cout<<fact;
}
int rec(int x)
{
    int f;
    if (x==1)
    return(1);
    else
    f=x*rec(x-1);
    return(f);
}

Write a program to show the concept of Merging in Data structure

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,k,i,j,item;
printf("enter n=");
scanf("%d",&n);
printf("enter array elements=");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter element to be inserted=");
scanf("%d",&item);
printf("enter location of new element=");
scanf("%d",&k);
j=n;
while(j>=k)
{
a[j+1]=a[j];
j--;
}
a[k]=item;
n=n+1;
printf("\nnew array is\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}

}

Write a program to show the concept of merging of tow array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[20],i,r,s,m;
int na=1,nb=1,nc=1;
printf("enter no. of array element of A\n");
scanf("%d",&r);
printf("enter array elements of A\n");
for(i=1;i<=r;i++);
{
scanf("%d",&a[i]);
}

printf("enter no. of array element of B\n");
scanf("%d",&s);
printf("enter array elements of B\n");
for(i=1;i<=s;i++)
{
scanf("%d",&b[i]);
}

while(na<=r&&nb<=s)
{
if(a[na]<b[nb])
{
c[nc]=a[na];
nc=nc+1;
nb=nb+1;
}
else
{
    c[nc]=b[nb];
    nc=nc+1;
    nb=nb+1;
}
}
if(na>r)
for(i=nb;i<=s;i++)
{
c[nc]=b[i];
nc=nc+1;
}

else
{
for(i=na;i<=r;i++)
{
c[nc]=a[i];
nc=nc+1;
}
printf("merged array is\n");
for(i=1;i<=s+r;i++)
{
printf("%d\n",c[i]);
}
}
}

Write a program to show the PUSH method in Data Structure

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10],max=10, i, n, tos , item;
    printf("enter no. of elements=");
    scanf("%d",&n);
    printf("enter array elements\n");
   
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    tos=n;
    if(tos>=max)
    {
        printf("overflow");
        exit;
   
    }
    else
        {
        printf("enter item to be inserted=");
        scanf("%d",&item);
        tos=tos+1;
        a[tos]=item;
        printf("new stack\n");
        for(i=1;i<=tos;i++)
        {
            printf("%d\n",a[i]);
        }
        }
   
       
        }

Tuesday, 2 July 2013

Write a program to show the concept of Array of Object in C++

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class biodata
{
    public:
    char name[20];
    int roll;
    public:
    void get()
    {
        cout<<"enter name and roll no. "<<"\n";
        cin>>name>>roll;
    }
    public:
    void put()
    {
        cout<<name<<setw(4)<<roll;
        cout<<"\n";
    }
};

void main()
{
int i,j;
cout<<"enter no. of entries";
cin>>j;
class biodata obj[20];
for (i=1; i<=j ; i++)
{
    obj[i].get();
}
cout<<"\n";
for (i=1; i<=j ; i++)
{
    obj[i].put();
}
}
       

Write a program to show the concept of POP operation in Data Structure

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10],min=0, i, n, tos , item;
    printf("enter no. of elements=");
    scanf("%d",&n);
    printf("enter array elements\n");
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    tos=n;
    if(tos==min)
    {
        printf("underflow");
        exit;
   
    }
    else
        {
        printf("top element is always deleted\n");
    item=a[tos];
    tos=tos-1;
        printf("new stack\n");
        for(i=1;i<=tos;i++)
        {
            printf("%d\n",a[i]);
        }
        }
   
       
        }

Write a program to show the concept of static member function in C++

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class account
{
    static int count;
    public:
    static void display()
    {
        count++;
        cout<<"the value of count="<<count<<endl;
    }
};
int account::count=50;
void main()
{
    account obj1, obj2;
    account::display();
    account obj3;
    account::display();
}

Write a program to show the concept of Inline Function in C++

#include<iostream.h>
#include<conio.h>
inline float area(float r)
{
    return(3.14*r*r);
}
void main()
{
    float radius, a ;
    cout<<"enter the radius of circle:";
    cin>>radius;
    a=area(radius);
    cout<<"the area of circle="<<a<<"\n";
}

Write a program to show the concept of Constant Member Function in C++

#include<iostream.h>
#include<conio.h>
class date
{
    int day;
     int month;
     int year;
     public:
     void getdata(int a , int b ,int c)//define function
     {
         day=a;
         month=b;
         year=c;
     }
     void display(void)const//define const function
     {
         cout<<"date is "<<day<<"-"<<month<<"-"<<year;
        cout<<"\n";
     }
};//end of class definition
void main()
{
    date birthday;
    birthday.getdata(15 ,11, 19);
    birthday.display();
}

Write a program to show the concept of Friend Function in c++

#include<iostream.h>
#include<conio.h>
class two;//forward declaration
class one
{
    int m;
    public:
    void getdata()
    {
        cout<<"enter the value for m:";
        cin>>m;
    }
    friend int sum(one,two);
};//end of class one definiton

class two
{
    int n;
    public:
    void getdata()
    {
        cout<<"enter the value for n:";
        cin>>n;
    }
    friend int sum(one,two);
};//end of class two
int sum(one a, two b)//definition of friend function
{
    return(a.m + b.n);
}
void main()
{
    one x;
     two y;
     x.getdata();
     y.getdata();
     cout<<"sum="<<sum(x,y);//calling friend function
}



Monday, 1 July 2013

Linier Searching technique in Data structure program with flowchart and algorithm

ALGORITHM

VARIABLES:

§  A:    array name.
§  N:   number of elements in array.
§  Item:      value to be searched.
§  Loc: location of item to be searched.


    ALGORITHM:

STEP 1:    Set a [n+1] = item
STEP 2:    Set LOC = 1
STEP 3:    Repeat while a [loc] != item
                 LOC = LOC + 1
STEP 4:    If LOC = N+1 then,
                 Search is successful
                 else
                 LOC = 0 & search is unsuccessful
STEP 5:    Exit


EXPLANATION:

§  To start the linier search, its is first assumed that the ITEM is inserted into array at the last location N+1
     as                   A [N+1] = ITEM

§  Then, the location counter ‘LOC’ is set to 1, to start the search, the value of the variable to be searched would be started from 1.

§  The location counter is them incremented, till the location of value to e searched becomes equal to the location counter.

§  If the location counter becomes equal to (n+1), then, the value to be searched is present at that location and the search is successful, otherwise, the location counter becomes ‘zero’ and the search is unsuccessful
       IMPLEMENTATION:


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,item;
printf("enter n");
scanf("%d",&n);
printf("enter array elements");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter search item");
scanf("%d",&item);
for(i=1;i<=n;i++)
{
if(item==a[i])
{
printf("item present");
goto end;
}
}
goto ss;
ss:printf("item not present");
end:getch();
}