Friday, 18 January 2013

Link list in c++

              /*LINKED LIST IMPLEAENTATION*/

                #include <iostream>
                #include <conio>
                /*=================================*/

                   struct node

               { int data;

               node *link;

               };


               node *head=NULL;
                          /*=============================*/


                            void main()
                        { void append();
                          void insert();
                          void delet();
                          void display();

                          int opt;
                         while(1)
                         {
                          cout<<"1:append\n";
                          cout<<"2:nsert\n";
                          cout<<"3:delete\n";
                          cout<<"4:display\n";
                          cin>>opt;

                          switch(opt)
                       {
                          case 1:
                          append();
                          break;
                          case 4:
                          display();
                          break;


                       }


                       }










                        getch();}        /*==================================*/




                           void append()
                        {
                          node *t,*n=head;
                          t=new node;

                          cout<<"Enter element \n";
                          cin>>t->data;
                          t->link=NULL;
                          if(head==NULL)
                           head=t;
                           else
                        { while(n->link!=NULL)
                           {
                              n=n->link;
                              n->link=t;
                           }




                        }   }




                        void display()
                     {   node *n=head;
                       if(n==NULL)
                       cout<<"list is empty\n";
                       else
                    {
                      while(n!=NULL)
                      {cout<<n->data<<"     ";

                      n=n->link;
                      }cout<<endl;
                    }




                     }






0 comments:

Post a Comment