Page 102 - DCAP407_DATA_STRUCTURE
P. 102

Unit 6: Linked List Operations



                               int PTR, NUM, NUM_LOC;
                               Clrscr();
                               LIST[0] =55;
                               LIST[2]=10;
                               LIST[3]=19;
                               LIST[5]=60;
                               LIST[7]=35;
                               LIST[8]=20;
                               LIST[9]=8;
                               LIST[11]=12;
                               LIST[13]=45;
                               LIST[14]=68;
                               LIST[16]=75;
                               LIST[18]=80;

                               LIST1[0]=3;
                               LIST1[2]=13;
                               LIST1[3]=2;
                               LIST1[5]=8;
                               LIST1[7]=14;
                               LIST1[8]=9;
                               LIST1[9]=18;
                               LIST1[11]=16;
                               LIST1[13]=5;
                               LIST1[14]=-1;
                               LIST1[16]=0;
                               LIST1[18]=7;

                               HEAD = 16;
                               PTR=HEAD;
                               printf(“Traversed List:\n);
                               While(PTR!=-1)
                               {
                               printf(“%d/t”, LIST[PTR]);
                               PTR=LIST1[PTR];
                               }
                               printf(“\n\n Enter the number to search”);
                               scanf(“%d”, &NUM);
                               NUM_LOC=SEARCH(NUM);
                               if(NUM_LOC==-1)
                               printf(“\n number is not present in the list”);
                               else
                               printf(“\n number %d is present at index location %d in the  list”, NUM,
                               NUM_LOC);
                               getch();
                               }
                               int SEARCH(int I)
                               {
                               int p=HEAD;
                               int L=-1;
                               while(p!=-1)
                               {
                               If(I==LIST[p])
                               {
                               L=p;
                               break;
                               }




                                        LOVELY PROFESSIONAL UNIVERSITY                           95
   97   98   99   100   101   102   103   104   105   106   107