Docstoc

pro3

Document Sample
pro3 Powered By Docstoc
					  #include<stdio.h>
               #include<conio.h>
               typedef int list;
               struct node
                 {
                      list data;
         struct node *link;
    } *p;
    list n,c;
    void append();
    void del();
    void disp();
    void insert();

               void main()
                 {
                  list choice;
                 clrscr();
                 do
                  {
                      clrscr();
                      printf("\n1.Addnode\n 2.Deletenode\n 3.Insertnode\n
4.Display\n 5.Exit");
                      printf("\nEnter the choice:-");
                      scanf("%d",&choice);
                    switch(choice)
                        {
                           case 1:
                                 append();
                                 break;
                                   case 2:
                                   del();
                                   break;
                                               case 3:
                                insert();
                                break;

                        case 4:
                                  disp();
                                  break;


                        case 5:
                                 exit(0);
                       }
                    } while(choice<5);
                 getch();
             }

           void append()
             {
                  struct node *q,*t;
                  printf("\n Enter the Data to add");
                  scanf("\n %d",&n);
    if(p==0)
     {
        p=(struct node*) malloc(sizeof(struct node));
        p->data=n;
        p->link=0;
     }
  else
     {
        q=p;
        while(q->link!=0)
        q=q->link;
        t=(struct node*) malloc(sizeof(struct node));
        t->data=n;
        t->link=0;
       q->link=t;
     }
   getch();
}
void del()
   {
       struct node *q,*r;
       q=p;
       printf("\n Enter the Data to be Deleted");
      scanf("\n %d",&n);
      if(q->data==n)
        {
           p=q->link;
           free(q);
           return;
        }
    while(q!=0)
    {
          if(q->data==n)
           {
               r->link=q->link;
               return;
             }
          r=q;
        q=q->link;
    }
      printf("\nELEMENT NOT FOUND");
      getch();
 }
void insert()
   {
      struct node *q,*t,*r;
      list i;
      printf("\n Enter the position to be Inserted:");
      scanf("\n %d",&c);
      printf("\n Enter the Data:");
      scanf("\n %d",&n);
      for(i=0,q=p;i<c;i++)
        {
           q=q->link;
          if(q==0)
          printf("\n There are less then %d elements",q);
         }
    r=p;
   while(r->link!=q)
   r=r->link;
   t=(struct node*) malloc(sizeof(struct node));
   t->data=n;

 t->link=r->link;
   r->link=t;
   getch();
 }
void disp()
     {
          struct node *q;
          for(q=p;q!=0;q=q->link)
          printf("\n %d",q->data);
          getch();
     }

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:10/18/2012
language:Unknown
pages:3