Sie sind auf Seite 1von 65
DATA STRUCTURES INDEX SR.NO. CONTENT SIGNATURE 1. Write a program create a Stack & add elements into the stack,delete elements from the same stack. 2. Write a program to create a Stack. | 3. Write a program to create a Queue , add elements into the queue & delete elements from the same queue. Prod 4. Write a program to create a Queue. 5. Write a program to to traverse binary tree - in: 1) Inorder form 2)Pre-order form 3 )Postorder form ( 6. Write a program to count the leaf nodes in - binary tree. a, Write a program to create a Single Linked List, Insert & Delete elements from it. 8. Write a program to create a single linked list. 9. Write a program to implement Bubble Sort 10. Write a program to implement Heap Sort 18 Write a program to implement Insertion Sort 12. Write a program to sort the given numbers by using Bubble sort technique. 13, Write a program to join circular linked lists. (G : ( pepe 14. Write a program to join single linked lists. “Fracti cat No 31 Croake oe & ddd elemeats fata the steok Delete elements fa the same. lyaxtth oo 2 Create Steck Pre + stack clement Cootiiiassfee 04 stuck Post : Idee ob fade Aiea alfarated ds czas sii Rehun : Potntee Ie hewcl node ar null _pototee 2 No memar 1 Ph (om. ORY mit ef vail hie) _ fy Stackphr <2 oulp else A GWlereke Zetackpn) (Head! gitocatead. /ee geal tatHabfee £ sllacete stuck aexdef) fi) Shockph unt =o_ Sui tock p be inp = =) jv) stutkphe rockmax = stock elem fF ( memorye not avafloble) a) ede fe Cskuelxpbe) epull vw) Alse ( Atte ey eto) — AD ) Rehwo ge ne he A) kad FOR EDUCATIONAL USE, Algacttha 2 Add element [am the tock (push Ly short \f Top = size -| then CTop fs ptr dm potas Lop anest ebook ob stro 1) Dfsabay “steuls OverAlous hp Batt 4) Else Top =Toe +! 4) A(Toe) = n ( Obsiz€) pre damens =) fF xT 4 xfhhen 2 Delete element faoar stele ( Pag ) Shor} = If Top < 0 Men $> Di: 4 cle fi ¥ Tp Baeth 3) Fise Bemovt phe bop mast element. 4) N Practical no. 1 Hinclude int stack[50] item; int ch,n=0,top,i; void main() { void createQ); void add(); void deletelast(); void display; do { clrscr(); printf("\n\t Stack Operations \n't"); printf("\n-— printf("\n\n n\n"); 1 Create \n\n 2.Add \n\n 3,Delete\n\n 4.Display\n\n 5.Exit\n\n"); printf("\nEnter Your Choice:"); scanf("%d",&ch); printf("Enter maximum size for stack :"); scanf("%d",&n); case 1: create); getch(); break; case 2: add(); getch(); break; case 3: deletelast(); getch(); break; case 4: display(); getch(); brea case 5: exit(); getch(); break; default: printf("Invalid choice "); break; if(ch==1) t ) switeh(ch) t ) gotch(); } while(ch!=5); } void create() { printf("\n\t Create a Stack :"); printf("\n stack is created !"); return; I void add() { _ printf("\n Adding element to stack "); printf(" n\n"); printf{"Enter item to be inserted into stack scanf{"%d",&item); if(top==n) { _printf("Stack ios full cant insert !"); getch(); return; } top; stack{top]=item; printf("\n Item %d has been inserted into stack" item); return; } void deletelast() { _ printf("\nDeleting element from stack :\n"); printf("Stack is empt getch(); retum; —} item=stack[top]; top--; printf("\nltem %d is deleted from stack" item); printf{"\nltems of stack are:\n"); for(i=1;i #include #include struct stack { int data; struct stack *next; hb struct stack *pop(struct stack *top); struct stack *push(struct stack *top); void main() { struct stack *top; int reply,option,data; - lrser(); top=NULL; do { printf{"\nStack Operations: \n"); printf("~ "Ys printf("\n push \n 2.pop \n 3.exit\n\n"); printf("Select Your option:"); scanf("%d",&option); switch(option) { case I:top=push(top); break; case 2:top=pop(top); break; case 3: exit(0); break; } 3 while(1); struct stack *push(struct stack *top) { } struct stack *c; o=(struct stack*)malloc(sizeof{struct stack)); if(e==NULL) { printf("\nInsufficient Memory !"); return(top); J printf("\nEnter data: "); scanf("%d" &e->data); c->next=NULL; printf("\n\tTha Data item %d has been pushed into the stack \n\n",c->data); if(top=NULL) { top=<; else c->next=top; top=c; } return(top); struct stack *pop(struct stack *top) { struct stack *c; if(top-=NULL) x printf("stack is empty"); return(top); 3 printf("\n\t Popped data is: %d\n\n"top->data); top; retun(top); FRacticar No 2 3 | Create a Queue 6 Adel element falo the —__ Pas 3 hi oad ban betel |allevabed 2 fatitathg aaa Rehons heud's oldress FA succersshd ,nul Ph e overtler _ | Steet fk_( memory —averfleble) a) allocate C neroptr) — b)_newpt-> bmat = oulh ©) theo phy nee = null dh) pep > count Zp @) 2ehero newt ) ise @) vehwn ull pofarer. 4) Bef. FOR EDUCATIONAL USE Al 2Eh 2 Addl el fo 4 0. | i stew b 2 SInehralfee FRont = -) , RPAR = -) | Po_varidble 'n\! A Ik (RepR >= size) 7 f> Display "@ueue Oyertlow" | 422 £xfh SS) glse es | or f> REAR = REAR +) _ = 4\ #( REAR) =~ TD Axi 6 2 Delebe clements fro te queue | Ce | S) s terk s = If (RAAR ¢ FRort) i 7 FRps oa oe | ib _Drspl. “@ eo _uncderflan” iy Ax fh Blse ° f> N 2 A ( FRonr) 4) FRboNT £ FRONT 4) ) Bact FOR EDUCATIONAL USE Practical no. 3 #include #include #include int queue[S0},item; int ch,n=0, front,rear,i; void main() { void create(); void add(); void deletelast(); void display(); do { clrser(); printf("\n Queue operations\n"); printf("\n - ln"), printf("\n 1.Create \n\n 2.Add \n\n 3.Deletelast \n\n 4,Display\n\n 5.Exitin"); printf("\n Enter Your Choice:"); seanf{"%d" Sch); if{ch—=1) { printf("\n Enter maximum size of queue you wish to have:"); scanf("%d",&n); } switch(ch) { case L:create();getch();break; case 2:add();getch();break; case 3:deletelast();getch()sbreak; case 4:display();getch();break; case S:exit(0);getch();:break; default: printf("Invalid choice! Try again "); getch();break; } void create() { printf("\n\nCreating a Queue.. printf("\n -\n. front=0,rear—0; printf("\n\nQueue created"); return; } void add() { if(tear>=n) { printf("Queue is full 1"); getch(); return; } else { printf("\nAdding element into a queue"); printf(" "); printf("Enter item to be inserted : "); scanf("%d",&item); reart+; queue[rear]=item; if{(front—=0) front=1; printf(""\n\nltem %d has been inserted into queue’ item); printf("\n Items of queue are:"); for(itront;i<=rear;i++) { printf("\1%d",queuefi)); 3 return; 3 } void deletelast() { printf"\nDeleting element from queue\n"); printf("\n "5 printf(""\nQueue is empty !"); getch(); return; } front++; item=queue[front]; printf("\n Item %d has been deleted from queue" tem); printf(""\n Items of queue are:"); for(i=front;i<—tear;i++) { printf("'1%d",queuefi]); } return; } void display() { printf("\n display all elements of Queue\n"); printf("\n Items of queue are:"); for(i=front;i<=rearsi++)_ { printf("\t%d" queuefi]); } return; Gases Queue overat ion: reece eet ep rSccre ees cee ery Eee eee cere ee eee eect cc torts reece eae cies Gicciieies ere Ferd Pacey Eee rra ne Perce Bao eee tone Deleting elenent from queue Diet oe oC eto ec) ete Fractal No $4 al - || bbefre a progaam fo Create a Queue + | Algorfrhos 5 _Cresste Queue | Th clgoxftha alle cater _memoxy for queue | heal: The pofater are set ho null < counter Te20- Allacates mememy tora queue head _pacle brom_dynamte _memarp £ 2chuns fh delebress to Hhe certler . | Pret _nabhtag least shee! has been allocated £ fothtalPoed | Kehun: heads adldees fk succersh nutl PP overblow+ » trot a # ¢ memary avaflable) fy allocate (newpte) ih pew ptr > front 2 null i i> newmptr > year = nub/ fo newpb aunt sO vy Rebwn nerrphe eherp rulf BS) flae ly) Ext FOR EDUCATIONAL USE, Practical no. 4 #include #include #define max 3 int queue[max},data; int front,rear,reply,option; void main() t elrser(); front=rear=-1; do t Prinf('\nQueue Operations : \nln\tl Insert into Queue \n\n\t2.Delete from Queue \n\n\t3.Exit\n"); printf("\n\n\tEnter Your choice: "); seanf("%d", option); switch(option) case I: printf("\nEnter data to insert:"); scanf("%d", data); reply=insertq(queue,crear,&data); if{teply-=-1) printf("'Queue is full!"); else Printf("Data %d inserted into Queue successfully !\n\n",data); break; case 2: reply=deleteq(queue, &rear,&data); if(teply==-1) printf("Queue is Empty!"); else printf("Data %d is deleted....\n\n" data); break; case 3:exit(0); default: printf("Invalide choice..Try again "); break; while(1); 3 int insertq(int queue{max],int *rear, int *data) { if(*rear—= max-1) retum (-1); else *rear=*rear+1; queue[*rear]=*data; return (1); int deleteq(int queue[{max],int *front, int *rear,int *data) { if(*front—*rear) return (-1); else (Hront) +; *data-queue[*front]; return(1); area FOR EDUCATIONAL USE Pre - Order Trevercot 2 La pre-order priversal, the 22ok pode fs__procersed Part, Pallowed by tes subhee — & then 2fghk Ub bree. o Algoxtthari Prearde Cyol ret 2 node parfoters) Bavese a _hbfamy tree fo nade -lofh ~ _ vi wen. Prt_2 rook fs the €obey node ot o_fte or subbee 2 2 eath ode has beea poatedsod foordee PEC 2ok fs nok null) 2. ix Process Craot) if» preorder (200b = left subb-e) ‘iin Prrarcle ook _pigh+ subbte) —____ » Rehr» FOR EDUCATIONAL USE, AL fi & pasty: i “Prdwers 2 a binary p> fa =a2ighk- euuernce » Pret 200k fs the coop pade cf bee 92 -sclbhre post + each node Aa been praced.ted fa trdee i> fA ( 20or fs not nub) {> Pastordes Croat > lebhsubbie) > eostnrder Anak =~2_2Sghtsih te) __ ea it process (r0ot) 2) Rehon a FOR EDUCATIONAL USE, Practical no. 5 #include #includesstdlib.h> #include struct treeree { struct treerec *lchild; struct treerec *rchild; char data; hb struct treerec *item; struct treeree *rdata[50]; void main() { intin; clrser(); printf{""\nEnter no of data-items to be enterd in tree: "); seanf("%d",&n); printf(""\n\nEnter data-items: "); for(i=1;i<-mi++) { rdata{i}=(struct treerec *)malloc(sizeofistruct treerec)); scanf("\r%c", Serdatali]->data); rdatafi]->Ichild=NULL; rdatai]>rehild=NULL; } for(i=1;i<=n;i++) ti rdatafi]->Ichild-rdata[2*i]; rdatafi]->rchild=rdata[2"i+1]; } item=rdatafi; printf("\n\nGiven Data in Tree\n"); ‘atn"); n;i++) printf("%c\t"rdata{i]->data); printf("\n\n"); printf("Inorder tree traversal\n\n"); print{("*#sseesenansenanenaenneig\, inorder(item); print{("\n\nPreorder tree traversal\n\n"); print{("*ereerseenensenaesastseanien: preorder(item); printf("\n\nPostorder tree traversalin\n"); print{("eeeesernernerecteeeeseer ni); postordertitem); getch(); } inorder(cnode) struct treerec *enode; { if{enode!=NULL) { inorder(cnode->Ichild); if{cnode->data!=" ') { printi("%c" enode->data); } inorder(cnode->rehild); } return(1); $ preorder(cnode) struct treerec *cnode; { iffenode!=NULL) { inorder(cnode->Ichild); iffenode->data!="_’) { printf("%c" cnode->data); } preorder(cnode->Iehild); preorder(cnode->rehild); } postorder(cnode) struct treetee *enode; { if{enode!=NULL) { postorder(cnode->lchild); postorder(cnode->rchild); if{cnode->data!~"_") { printf("%c" cnode->data); } } return (1); PRacica, to 36 Wpfle a ot) eh2.0b 20. ; ty__counr leat nade fa _ binary tre Dlgoxct thor’ _getLeakGount Mode} JP node fs HuLl then 2ehun g child nodes are Nur ehun! 3) Blse 2ecurstyels calewabe leat count ot the leat foun) ba tree zlea! touat af lob) subbee + Leak count at right subbee A) Boefk FOR EDUCATIONAL USE Practical no. 6 Hinclude #include #include #include struct node { int data; struct node*left; struct nade*right; b unsigned int getleafcount(struct node* node) { if{node=NULL) return (getleafcount(node->lef)+ getleafcount(node->right)); 3 struct node*newnode(int data) t struct node*node=(struct node*)malloc(sizeof{(struct node)); node->data=data; node>left-NULL; node->right=NULI return(node); } int mainQ) {__ struct node *root=newnode(1); clrser(); root->left=newnode(2); root->right-newnode(3); 100t->left->left=newnode(4); root->left->right-newnode(5); printf"Leaf count of the tree is %d",getleafcount(root)); getch); return 0; Outpu: TRacncat No 27 | PL => || Algoxtthe, i (Crease Stagly lfaked esr a Ifsk mode £ rehuns fre gdalress tn caller } Ly Start 2> PEC memerp avaflable) Le Allocate ( PNew) | 2. PNeuw 2 heal Nu, | | 4: pNew >» Count =D Fis | pdew > oull 1 2) Rehun _pNer t ) Bach : FOR EDUCATIONAL USE Algaorxttha : losot a node oe v 1) Steep} > Input aki op _be_fnsezted 3) Creatke a Newttode temp 2) temp 3 DATA =n s) ft ( staat. NuLL) ternp > next = H, 6) Els temp > next = sTART seTeeQr ee hemp go) Exfr FOR EDUCATIONAL USE Al gust l- 4 eg nade 2 PTT = START 2D _STHaT = START 2 NE xp AD Free (ett) 5) bit Delete a pachtabler ode 1 Felack 2 Input nade which wou paot tn olelebe B® PTR = 4) Hhile ¢ —_ fot _cqutcd PTR 2 Date AND PTR 00 J PTT = PTR PTR = PTR Next oie PIT 2nexr = PTR > hext free (PTR) 6) Fl Display \ Bement pot Aruadl T> Pacfr FOR EDUCATIONAL USE. Practical no. 7 #include #include #include struct studinfo { int data; struct studinfo *next; B struct studinfo *start=NULL, *ptr, “disp; void insertnode(); void deletenode(); void display(); void main() { int ch; clrser(); do { printf("\n\n\tMenus\n\t-— -\n"); printf("\t1 Insert node \n\n\t2.Delete node\n\n\t3, Display\n\n\t4.Exit\n\n\t"); printf("Enter Your Choice:"); scanf("%d",&ch); fflush(stdin); switch(ch) { case 1: insertnode(); break; case 2: deletenode(); break; case 3: display(); brea case 4: exit(0); break; default:print{("Invalid choice entered ! Enter again"); break; 3 while(1); 3 void insertnode() { struct studinfo *newnode; newnode=(struct studinfo *)malloc(sizeof(struct studinfo)); printf("\Enter data of for the node to be inserted :"); seanf{"%d", &riewnode->data); ptr=start; if(start = NULL) { start=newnode; newnode->next=NULL; ptr=newnode; Printf("wn\tNewnode with data:%d inserted" newnode->data); else ptr->next=newnode; newnode->next=NULL; ptr=newnode; Printf("\n\tNewnode with data:%d inserted" newnode->data); } fflush(stdin); i void deletenode() { struct studinfo *del; iffstart==NULL) { printi("List is empty"); else ptrstart; start=start->next; free(ptr); printf("Deleted"); 3 void display() { sdlisp=disp->next) { if(pt=NULL) { printf("List is empty"); } else { ptr=ptr->next; printf("\n\tData: %d",disp->data); } } Sac Berar) Ge era Perera eer eee oe Peete Cette FRactcal No ik nies hizfte a _prngraa ho _crecthe Lest togly Ltaked. Algaxtthen § ! S shat bk » PAL New > heacl = null fi ¥ FOR EDUCATIONAL USE struct node *current; current = head; if(current!= NULL) { > do { printf("%d\t",current->data); current = current->next; 3 while (current!= head); printf("\n"); } else printf("The list is empty\n"); } void destroy(struct node *head) { struct node *current, *tmp; current head->next = NULL;_ while(current != NULL) 1ead->next; { tmp = current->next; free(current); current = tmp; } void main() { struct node *head = NULL; clrser(); head = add(head,1); printlist(head); head = add(head,20); printlist(head); head = add(head,10); printlist(head); head = add(head,5); printlist(head); destroy(head); getch(); Output: GX Practar No gusP hh on A - s lots ) ad ft: ae exthaageel Jot) Its fs completely ardesecd. 1) Stavt 2 Currenak =) > Saed < Fal PE Clfst © walked < Lise Lwaliser 1] Ie Sarked = fal. 2. A en -usclkces, worcil kee TD Walker = Jo th a ee End FOR EDUCATIONAL USE Practical no. 9 Hinclude #include void main() { int arr[5] = { 25, 17, 31, 13,2) 5 inti, j, temp ; clrser( ) 5 printf ( "Bubble sort.\n" ) ; printf ("\nArray before sorting:\n for (i=0;i<=4;i++) printf ("%d\t", arr[i] ) ; for (i=0;1<=3;it+) { for (j=03j<=3-isjt+) { if ( arr{j] > arr[j + 1) ) { temp = arr{j] ; arr{j] = arr{j +1]; arr{j + 1] = temp ; } } } printf ("\n\nArray after sorting:\n") ; for (i= O31 <=45 i++) printf ( "dit", arrfi] ) ; getch() 5 FRacncar. Nu_s lo | eye birtke a pragaam fre Mean sot —__ Algor hh an 3 g pep 'a' § -ca_array of 'o' elements 1> Strack Pe) 2) pinsle (je =n) a) tall InsertHeup (a,j ,alpeig) by j aj a 3) whfle (n> =\) a) ¢ull pelebeHeapt) a by any 2x =n =} A) Rath FOR EDUCATIONAL USE. i Practical no. 10 Hinclude include void makeheap (int [], int ); ‘Void heapsort (int [ ], int); void main( ) { } int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 90,3} 5 inti; elrser( ) 5 printf ( "Heap Sort.\n" ) ; makeheap (arr, 10) ; printf ( "\nBefore Sorting:\n" ) ; for (i= 0;1<=9; i++) printf ("%d\e", arr{i] ) ; heapsort ( arr, 10); printf ("\nA ter Sorting:in" ) ; for (i= 0;1<=9 5144) printf ("%d\t", arti] ) ; getch( ); void makeheap ( int x{ }, int n ) { inti, val, s, £3 for (i=1;i 0 && x[f] < val ) { xs] =x{f] s=f; f=(s-1)/2; } x{s] = val ; } inti, s, f, ivalue ; for(i=n-15i>03i-) { ivalue = x{i) ; xfi] = x[0] 5 f=0; if(i=1) s=-l; else s=1; if (i> 2 && x[2]>x[1]) while ( s >= 0 && ivalue i-1) 3 x{f] = ivalue ; i2_dP fe euth i fx list fs foserted fon sorted If~ 1>_ stort 2) Cumrenk = #include void main( ) { int arr{5] = { 25, 17, 31, 13,2}; int i j,k, temp ; elrser() 5 printf ("Insertion sort.\n" ) ; printf ( "\nArray before sorting:\n") ; for (i= 0;1<=4; i++) printf ("%d\t", arr{i) ) ; for (i= 15i<=45it+) { for(j=O3j arefi] ) { temp = arti] ; arr(j] = arr{i] 5 for (k=i;k>j;k-) arr[k] = arr[k- 1] 5 arr[k + 1] = temp ; } } } printf ("\n\nArray after sorting:\n") ; for (i=0;i<= 45 i++) printf ("%d\t", arr[i] ) ; getch() ; GRUrU Manag FRacticar No 212 ee 6) Ar( feo; Pee 85 ist) 20° = Bs yor) checl a rr fpa > arr tj +11) the ie} bem Sarr tjd, nee eee axa tai] © deme | ey, fotk ( “AT puis for (feo; fecu ; foe) vail order): >) Boefh _ = FOR EDUCATIONAL USE Practical no. 12 #include Hinelude void main( ) { inti, j,arr{50},temp; forli=O;i<5;i++) { printf("Enter no. %d: "\i+1); seanf("%d", Sarrfi]); } printf ("\nBubble sort.\n" ) ; printf ( "\n\nArray before sorting:\n\n\t") ; for (i=0;i<=4; i++) printf ("%d\t", arr{i] ) ; for (i=0;1<=3 i++) { for (j=03)<=3-i;j++) { if (arr{j] > arr{j + 1]) { temp = arrfj] 5 arr(j] = arr{j + 1] ; arr[j + 1]=temp ; } 3 } printf ("\n\nArray after sorting:\n\n") ; for (i=0;i<=4; i++) printf ("\%d", arrfi] ); getchQ; TRACICAL No 313 —ll ye a 13. = tak eal ile Blgortthes 2 abe ci , Le. 1) Stout Ia (reste a New Node Temp Temp > Pater = 4) Temp =» Next = strirt > Nex, )_ Stir} > a ——____ aan 6) £xft | Algorftho, To _fasert Doel, start \ Input Node t wPher which you wish ho enter PIR = Stes 3 next AD while (+ aor qual» PTR2 Dak BND PTR2n6. por equal tn stew k neat) PTA = PTR Next = Je Cb eqeretl bb PTR Date) Create a newned. emp Temp = Dake _=N Temp >Next = PTR Heath PTR > Next = Teme Sturt = Temp a) Display “Blemeat not found“ Feet t J FOR EDUCATIONAL USE Practical no. 13 Hinclude #include #include ‘define newnode (struct node*) malloc(sizeofistruct node)) struct node { int data; struct node *next; B struct node *start; struct node *create_list(); struct node *merge_list(struct node *f1, struct node *12); void main() t struct node *n1,*n2,*n3; int len,reply; nl =n2=NULL; clrser(); printf("\n\n\titloin 2 circular Lists\n\n"); printf("\nEnter first circular linked-list\n");, nl = create list; printf("\nEnter second circular linked-list\n"); n2 = create list; printf("\n\nin First list is: \"); print_list(n1); printf("\n\n Second list is: \"); print_ist(n2); n3 = merge _list(n1,n2); printf("\n\n\nThe resultant joint list "ys print_list(n3); getch(); } lf main struct node *create_list() { int tdata; f£=NULL; printf("\n Enter data ( use 0 to exit): "); scanf("%d",&tdata);, while( tdata != 0 ) { ¢=newnode; if{ == NULL) { printf{"\n Insuf. mem. "); exit(0); 3 data = tdata; next = NULL; if(-= NULL) feo; else penext = ¢; pac printf(("\n Enter data (use 0 to exit): "); scanf("%d",Setdata); } return(f); print_list( struct node *f) { struct node *t; iftf = NULL) { rintf("List is empty"); return; 3 t=f while (t != NULL) { printf("%4d",t->data); t=t>next; return; struct node *merge_list(struct node *nl, struct node *n2) { int reply; struct node “1,2; if(al == NULL && n2 return(NULL); else if(nl != NULL && n2 == NULL) return(nl)s else NULL && n2 != NULL) return(n2); th=nl; while (1>next != NULL) { tl = tl->next; } tI->next =n2; return(nl); a EEC Eat ed 303_ a a a f. ; bye jototoq of Maled LP. | Algustthen 2 1) Shert > Declavt shuchue “nade" wth date members det of syne Fatey tert of hype struct Ood Nedarye len 6) tor Perse Ifabed lest data fa ni; by the stakement 11 = Create lise); 2) Ask use» pp cater second Ifaked Irs data __ Short _sctond Jfaked |fs+ data fan b4 Stakement 2 = (vrate—lfsi() 3) fi G rspCos) y prlor_tist2 by calling prfiarist (ar); 4) Merge hua lRaked tsk £ stre_fo n2_by Wing | imi, Nas jain ltst (Oy4n2)/: ho) PrYor 26 cullen list by ding + peta list las), End mafat) FOR EDUCATIONAL USE. nocle+ Declare 5 faheyer phat 'hodophe! sek f= Null 15) Ask wee fy enter dakn fox |Poked Ifst to. dolder_ta_*telotha! 14) Jihfle (tebe 20) eC = nes noole cChetk pf Cc = = Null) " petarh (Insubbres ") ‘exfE(o): = eet > dota « datn’ ek C > neat = null: 1s) thes PA CF er P else er p >next =C, P= i 16) Aquat arabe 'tdolte! rehuo (Ph) fad functoo $7) Fun chon. ir S cletlare sheuck nade *b; 18) ¢theck %#(f ==Null) then _ pata (“list @s eanphy"), er ts pL I 14) dihfle C+) =Nult) Q2tofl +> data); FOR EDUCATIONAL USE assign t= b> nexek | __zeherr. Lad fincko 20) Fundfen shasch node ¥ jata list truck nocle x01) hack node #n2) | cleslare _foteyer "reply" Jeclape 2 potaher #b1, #7 pochve oes node: Ibi) Chek Pf (nt= Nut 22 2 == null) thea 2chen (oui!) | else | heels (0) != Null ge 2 22 Null) then eh (o)’ else heels Pen! => uy £2 021 =Nutt) thea _2ehea (02); tls er tient _ 4 while Uti > nest Js I ebb) etl 3 nett 2s sek +t\ > next =n _2ehvn (no) 2S) Pett. FOR EDUCATIONAL USE #include #include #include #define newnode (struct node*) malloc(sizeof(struct node)) struct node { int data; struct node *next; ‘ struct node *start; struct node “create list(); struct node *join_list(struct node *f1, struct node *f2); void main() { struct node *f1,"£2,*£3; int len,reply; fl = f2= NULL; clrser(); printf("\nEnter first list\n"); fl = create list(); printf(""\Enter second list\n"); £2 = create list; printf("\n First list is\n"); print_list(fl); printf("\n Second list is\n"); print_list(f2); £3 = join_list(f1,f2); print{("\nThe resultant list is \n"); print_list(f3); zetch(); } struct node *create_list() { struct node *f,*c,*p; int tdata; f=NULL; ee ee a { c= newnode; if(e—= NULL) { printf("\n Insuf. mem. exit(O); } data = tdata; e->next = NULL; if{ f= NULL) prg printf("\n Enter data (use 0 to exit ) : seanf("%d" getdata); } return(f); } print_list( struct node *f) { struct node *t; int ULL) { printf("List is empty"); return; } a f while (t != NULL) { printf("%4d",t->data); next; } return; } struct node *join_list(struct node *f1, struct node *£2) { int reply; a else if( fl != NULL && f2 == NULL) return(f1); else if( f1 = NULL && f2 != NULL) retur(£2); else { =f; while (t1>next != NULL ) { t1=t>next; } tl>next = £2; return(fl); }

Das könnte Ihnen auch gefallen