Page 104 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 104

Unit 7: Linked Lists




          #include<conio.h>                                                                     Notes
          struct single_link_list
          {
            int age;
            struct single_link_list *next;
          };
          typedef struct single_link_list node;

          node *makenode(int );
          int main()
          {
            int ag;
            node *start,*last,*nn;   //nn=new node
            start=NULL;
            while(1)
            {
               printf(“Enter your age : “);
               scanf(“%d”,&ag);
               if(ag==0)
                  break;
               nn=makenode(ag);
               if(start==NULL)
               {
                  start = nn;
                  last = nn;
               }
               else
               {
                  last->next = nn;
                  last = nn;
               }
            }
            printf(“\n\t****Single linked list****\n\n”);
            for(; start!=NULL; start=start->next)
               printf(“%d\t”,start->age);
            getch();
            return 0;
          }

          /*creation of node*/

          node *makenode(int tmp)
          {
            node *nn;





                                           LOVELY PROFESSIONAL UNIVERSITY                                   97
   99   100   101   102   103   104   105   106   107   108   109