Upload
avinash-bharadwaj-g
View
226
Download
0
Embed Size (px)
Citation preview
7/25/2019 Data Structure Lab11.PDF
1/70
INDEXSL.N
O
NAME OF THE
PROGRAM1. a) Write a C Progra to !ti"#ate t$e
to%er o& Ha'oi (ro#e.) Write a C Progra to i(#ee't!ta*+ "!i'g arra,!.
-. Write a C Progra to *o'ert a' i'/0e0(re!!io' to (o!t/0 &or.
. Write a C Progra to *o'ert a' i'/0e0(re!!io' to (re/0 &or.
2. a) Write a C Progra to !ort e#ee't!"!i'g I'!ertio' !ort.) Write a C Progra to i(#ee't3"e"e "!i'g arra,!.
4. Write a C Progra to *reate a !i'g#,#i'+e5 #i!t to (er&or t$e&o##o%i'g o(eratio'!.a)I'!ert &ro't)I'!ert !(e*i/e5 (o!itio'*)De#ete &ro't5)De#ete !(e*i/e5 (o!itio'e)Di!(#a,
6. Write a C Progra to !ti"#ate !ta*+"!i'g !i'g#, #i'+e5 #i!t.
7. Write a C Progra to !ti"#ate 3"e"e"!i'g !i'g#, #i'+e5 #i!t.
1
7/25/2019 Data Structure Lab11.PDF
2/70
8. Write a C Progra to *reate a *ir*"#ar!i'g#, #i'+e5 #i!t to (er&or t$e&o##o%i'g o(eratio'!a)I'!ert &ro't)I'!ert Rear*)De#ete &ro't5)De#ete Reare)Di!(#a,
9. Write a C Progra to *reate a 5o"#,#i'+e5 #i!t to (er&or t$e&o##o%i'g o(eratio'!a)I'!ert &ro't)I'!ert Rear
*)De#ete &ro't5)De#ete Reare)Di!(#a,
1:. Write a C Progra to *reate a 5o"#,#i'+e5 #i!t to (er&or t$e&o##o%i'g o(eratio'!a)I'!ert &ro't)I'!ert !(e*i/e5 (o!itio'
*)De#ete &ro't5)De#ete !(e*i/e5 (o!itio'e)Di!(#a,
11. Write a C Progra to *reate a *ir*"#ar5o"#, #i'+e5 #i!t to (er&ort$e &o##o%i'g o(eratio'!a)I'!ert &ro't)I'!ert !(e*i/e5 (o!itio'
*)De#ete &ro't5)De#ete !(e*i/e5 (o!itio'e)Di!(#a,
1-. Write a C Progra to *reate a i'ar,tree.
1. Write a C Progra to *reate a i'ar,!ear*$ tree a'5 (er&or tree traer!a#!Preor5er; I'or5er a'5 Po!tor5er.
12. Write a C Progra to *reate a i'ar,!ear*$ tree a'5 !"((ort t$e i'!ertio'
2
7/25/2019 Data Structure Lab11.PDF
3/70
a'5 5e#etio' o& a 'o5e.14. Write a C Progra to ea#"ate a'
e0(re!!io' "!i'g i'ar, tree.16. Write a C Progra to *reate a rig$t
t$rea5e5 i'ar, tree a'5 traer!e
i'or5er.
1.a) CLEM
3
7/25/2019 Data Structure Lab11.PDF
4/70
#include#includevoid tower(char src,char temp,char dst,int n);int main(void){
int n;clrscr();scanf(!d,"n);tower(a,$,c,n);return(%);&void tower(char src,char temp,char dst,int n){if(n>%){tower(src,dst,temp,n'1);printf(ove dis !d from !c to !c*n,n,src,dst);tower(temp,src,dst,n'1);&&
+--/
0
7/25/2019 Data Structure Lab11.PDF
5/70
3ove dis 1 from a to cove dis 2 from a to $ove dis 1 from c to $ove dis 3 from a to cove dis 1 from $ to aove dis 2 from $ to c
ove dis 1 from a to c
1.) C PROGRAM TO IMPLEMENT STAC? =SING ARRA@S
#include#include#dene sie
int stac43%5, top6'1, ch61, choice;void main(){
7/25/2019 Data Structure Lab11.PDF
6/70
printf(78tac operations*n9);while(ch){printf(7:rra implementation*n9);printf(71.ush*n9);printf(72.op*n9);
printf(73.ispla*n9);printf(70.=it*n9);printf(7=nter the choice*n9);scanf(7!d9,"choice);switch(choice){case 1/ push();$rea;case 2/pop();$rea;case 3/displa();$rea;case 0/eit(%);default/printf(7?ron@ choice*n9);&printf(7o ou want to @o arra implementation a@ain*n9);scanf(7!d9,"ch);& &push(){if(top66(sie'1)){printf(78tac is full*n9);return;&printf(7=nter the element*n9);scanf(7!d9,"num);stac4AAtop56num;
return;&pop(){if(top66'1){printf(7Bo elements in the stac*n9);return;
&printf(7opped element is !d*n9,stac4top5);
C
7/25/2019 Data Structure Lab11.PDF
7/70
top'';return;&
displa(){
int i;if(top66'1){printf(7Bo elements in the stac*n9);return;&printf(78tac elements are*n9);for(i6top;i>6%;i'')printf(7!d*n9,stac4i5);return;&
+--/8tac operations:rra implementation1.ush2.op3.ispla0.=it=nter the choice1=nter the element23o ou want to @o arra implementation a@ain1:rra implementation1.ush2.op
3.ispla0.=it=nter the choice0?ron@ choiceo ou want to @o arra implementation a@ain1:rra implementation1.ush
2.op3.ispla
D
7/25/2019 Data Structure Lab11.PDF
8/70
0.=it=nter the choice1=nter the element0o ou want to @o arra implementation a@ain
1:rra implementation1.ush2.op3.ispla0.=it=nter the choice2opped element is 0o ou want to @o arra implementation a@ain1:rra implementation1.ush2.op3.ispla0.=it=nter the choice38tac elements are23o ou want to @o arra implementation a@ain0:rra implementation1.ush2.op3.ispla0.=it=nter the choice
0
E
7/25/2019 Data Structure Lab11.PDF
9/70
-.C PROGRAM TO CONERT AN INFIX EXPRESSION TOPOSTFIX FORM
#include#include#include#dene sie Cchar in42%5,post42%5,temp,stac42%5,sm$ol;int i6%, F6%, len@th, top6'1;void main(){clrscr();printf(=B-=G -H= IBJIK =KG=88I+B*n); scanf(!s,in); inLtoLpost(in,post); printf(IBJIK =KG=88I+B6!s*n, in); printf(+8-JIK =KG=88I+B6!s*n,post); & inLtoLpost(char in45,char post45) { len@th6strlen(in); push(#); while(i
7/25/2019 Data Structure Lab11.PDF
10/70
& push(sm$ol); $rea;
default / post4FAA56sm$ol; $rea; &iAA;
& while(top>%) { post 4FAA56pop (); & return;
&push(char sm$ol){stac4AAtop56sm$ol;return;&pop (){char sm$ol;sm$ol6stac4top''5;return(sm$ol);&preced (char sm$ol){
int p;switch (sm$ol){case O/ p63;$rea;case Q /
case R / p62;$rea;case A /
case ' / p61;$rea;case ( /case ) / p6%;$rea;
case # / p6'1;$rea;
1%
7/25/2019 Data Structure Lab11.PDF
11/70
&return(p);&
+utput /=nter in epression(aA$)
ost epression6a$A
.C PROGRAM TO CONERT AN INFIX EXPRESSION TOPREFIX FORM
#include#includeint top6'1, len@th,i6%,F6%,6%;char temp,sm$ol,in42%5,pre42%5,stac42%5;void main ()
{clrscr ();printf (=B-=G -H= IBJIK =KG=88I+B*n);scanf (!s, in);inLpre (in,pre);printf(IBJIK =KG=88I+B6!s*n, in);printf (G=JIK =KG=88I+B6!s*n, pre);@etch ();&
inLpre (char in 45, char pre 45){
11
7/25/2019 Data Structure Lab11.PDF
12/70
len@th6strlen (in);push (#);len@th6len@th'1;F6len@th;while(in4i5N6*%){
if (in4i566(TTin4i566))U'';iAA;&while(len@th>6){ sm$ol6in4len@th5; switch (sm$ol) { case )/ push(sm$ol);
$rea; case (/ temp6pop();
while(tempN6)) { pre4F''56temp; temp6pop(); & $rea;
case O/ case Q/ case R/ case A/ case '/ if (I8 (stac 4top5)>6IV (sm$ol))
{ temp6pop (); pre 4F''56temp; & push (sm$ol);
$rea; default/pre4F''5 6sm$ol;
$rea; & len@th''; & while (top>%) { -emp6pop ();
pre 4F''56temp; &
12
7/25/2019 Data Structure Lab11.PDF
13/70
return; & push (char sm$ol) { stac 4AAtop56sm$ol; return;
& pop () { char sm$ol; sm$ol6stac4top5; top''; return(sm$ol); & I8 (char sm$ol) { switch (sm$ol) { case OP/ return C; case Q/ case R/ return 3; case A/ case '/ return 1; case #/ return '1; case )/ return %;&return (sm$ol);& IV (char op){switch (op){case O/ return ;case A/
case '/ return 0;case Q/case R/ return 2;case )/ return %;case (/ return S;&return (op);&
+uput/'=nter in epression
13
7/25/2019 Data Structure Lab11.PDF
14/70
(aA$)
In6(aA$)re6Aa$
2.a)C
7/25/2019 Data Structure Lab11.PDF
15/70
7/25/2019 Data Structure Lab11.PDF
16/70
$rea; & Zinsert() { if(rear6(sie'1)) {
printf(stac is full*n); return; & else { int num; printf(enter the element to $e inserted*n); scanf(!d,"num); Y4rearAA56num; if(front66'1) frontAA; return; && Zdelete() {
if(front66'1){printf(no elementsRY empt*n);return;&else if(front66rear){ printf(element to $e deleted is !d*n,Y4front5); front6rear6'1; return; & else { printf(=lement to $e deleted6!d*n,Y4front5); frontAA;
return; &Zdispla()
{ int i;
if(front66'1) {
printf(no element*n); return;
& else
1C
7/25/2019 Data Structure Lab11.PDF
17/70
{ for(i6front;i>6rear;iAA) { printf(!d*t,Y4i5); & return;
&
O=TP=TB=E=E I(#ee'tatio'1.I'!ert-.5e#ete.5i!(#a,2.e0itE'ter ,o" *$oi*e1
E'ter t$e 5ata-B=E=E I(#ee'tatio'1.I'!ert-.5e#ete.5i!(#a,2.e0itE'ter ,o"r *$oi*e
-B=E=E I(#ee'tatio'1.I'!ert-.5e#ete.5i!(#a,2.e0itE'ter ,o"r *$oi*e-De#ete5 'o5e-
B=E=E I(#ee'tatio'1.I'!ert-.5e#ete
1D
7/25/2019 Data Structure Lab11.PDF
18/70
.5i!(#a,2.e0itE'ter ,o"r *$oi*e2
4. C Progra to *reate a !i'g#, #i'+e5 #i!t to (er&or t$e&o##o%i'g o(eratio'a)I'!ert &ro't )I'!ert !(e*i/e5 (o!itio'*)De#ete &ro't 5)De#ete !(e*i/e5 (o!itio'e)Di!(#a,
i'*#"5e!t5io.$i'*#"5e*o'io.$!tr"*t 'o5ei't 5ata!tr"*t 'o5e J#i'+Kt,(e5e& !tr"*t 'o5e JNODENODE /r!t:i't i;*$oi*e;*$11;*$oi*e1;*$-1;*$oi*e-;*$1NODE i'!ert&ro'tNODE /r!t)NODE i'!ert(o!NODE /r!t)NODE 5e#ete&ro'tNODE /r!t)NODE 5e#ete(o!NODE /r!t)
oi5 ai')*#r!*r)%$i#e*$1)(ri't&Si'g#, #i'+e5 #i!t o(eratio'')(ri't&1.I'!ert'-.De#ete'.Di!(#a,'2.E0it')(ri't&E'ter ,o"r *$oi*e')!*a'&5;Q*$oi*e)
!%it*$*$oi*e)
1E
7/25/2019 Data Structure Lab11.PDF
19/70
*a!e 1(ri't&I'!ert i(#ee'etatio'')*$-1%$i#e*$-1)(ri't&1.I'!ert Fro't')(ri't&-.I'!ert !(e*i/e5 (o!itio'')
(ri't&E'ter ,o"r *$oi*e')!*a'&5;Q*$oi*e1)!%it*$*$oi*e1)*a!e 1/r!ti'!ert&ro't/r!t) rea+*a!e -/r!ti'!ert(o!/r!t) rea+5e&a"#t(ri't&Wro'g *$oi*e')K(ri't&Do ,o" %a't to go to i'!ert i(#ee'tatio'
agai'')!*a'&5;Q*$-)Krea+
*a!e -(ri't&De#ete i(#ee'etatio'')*$1%$i#e*$1)(ri't&1.De#ete Fro't')(ri't&-.De#ete !(e*i/e5 (o!itio'')(ri't&E'ter ,o"r *$oi*e')!*a'&5;Q*$oi*e-)!%it*$*$oi*e-)*a!e 1/r!t5e#ete&ro't/r!t) rea+*a!e -/r!t5e#ete(o!/r!t)
rea+5e&a"#t(ri't&Wro'g *$oi*e')K(ri't&Do ,o" %a't to go to 5e#ete i(#ee'tatio'
agai'')!*a'&5;Q*$)Krea+
*a!e Di!(#a,/r!t)
rea+*a!e 2e0it:)
1S
7/25/2019 Data Structure Lab11.PDF
20/70
5e&a"#t(ri't&Wro'g *$oi*e')rea+
K(ri't&Do ,o" %a't to *o'ti'"e')!*a'&5;Q*$1)KK
NODE i'!ert&ro'tNODE /r!t)NODE 'e%'o5e'e%'o5eNODE)a##o*!ieo&NODE))'e%'o5e
7/25/2019 Data Structure Lab11.PDF
21/70
(ri't&I'a#i5 Po!itio'')ret"r'/r!t)Kte(1te(te(te(
7/25/2019 Data Structure Lab11.PDF
22/70
(ri't&De#ete5 'o5e5';/r!t
7/25/2019 Data Structure Lab11.PDF
23/70
1I'!ert i(#ee'etatio'1.I'!ert Fro't-.I'!ert !(e*i/e5 (o!itio'E'ter ,o"r *$oi*e1
E'ter t$e 5ata-Do ,o" %a't to go to i'!ert i(#ee'tatio' agai'11.I'!ert Fro't-.I'!ert !(e*i/e5 (o!itio'E'ter ,o"r *$oi*e1E'ter t$e 5ata2Do ,o" %a't to go to i'!ert i(#ee'tatio' agai'11.I'!ert Fro't-.I'!ert !(e*i/e5 (o!itio'E'ter ,o"r *$oi*e-E'ter t$e 5ata to e !tore5 i' t$e 'o5e26E'ter t$e (o!itio' %$ere t$e 'o5e i! to e i'!erte5-Do ,o" %a't to go to i'!ert i(#ee'tatio' agai':Do ,o" %a't to *o'ti'"e1Si'g#, #i'+e5 #i!t o(eratio'1.I'!ert-.De#ete.Di!(#a,
2.E0itE'ter ,o"r *$oi*e226-Do ,o" %a't to *o'ti'"e:
23
7/25/2019 Data Structure Lab11.PDF
24/70
6. C< PROGRAM TO STIM=LATE STAC? =SING SINGL@LIN?ED LIST
i'*#"5e!t5io.$i'*#"5e*o'io.$5e/'e !ie 6i't !ta*+U:V;to(
7/25/2019 Data Structure Lab11.PDF
25/70
(ri't&Do ,o" %a't to go to #i'+e5 #i!t i(#ee'tatio'agai'')!*a'&5;Q*$1)KK
NODE i'!ert&ro'tNODE /r!t)
NODE 'e%'o5e'e%'o5eNODE)a##o*!ieo&NODE))'e%'o5e
7/25/2019 Data Structure Lab11.PDF
26/70
(ri't&5;te(
7/25/2019 Data Structure Lab11.PDF
27/70
7. C PROGRAM TO STIM=LATE B=E=E =SING SINGL@LIN?ED LIST.
i'*#"5e!t5io.$
i'*#"5e*o'io.$!tr"*t 'o5ei't 5ata!tr"*t 'o5e J#i'+Kt,(e5e& !tr"*t 'o5e JNODENODE /r!t:i't '";rear
7/25/2019 Data Structure Lab11.PDF
28/70
NODE 'e%'o5e;te('e%'o5eNODE)a##o*!ieo&NODE))'e%'o5e
7/25/2019 Data Structure Lab11.PDF
29/70
O=TP=TB"e"e o(eratio'Li'+e5 #i!t i(#ee'tatio'1.I'!ert-.De#ete.Di!(#a,
2.E0itE'ter ,o"r *$oi*e1E'ter t$e 5ata-Do ,o" %a't to go to #i'+e5 #i!t i(#ee'tatio' agai'1Li'+e5 #i!t i(#ee'tatio'1.I'!ert-.De#ete.Di!(#a,2.E0itE'ter ,o"r *$oi*e1E'ter t$e 5ata24Do ,o" %a't to go to #i'+e5 #i!t i(#ee'tatio' agai'1Li'+e5 #i!t i(#ee'tatio'1.I'!ert-.De#ete.Di!(#a,2.E0itE'ter ,o"r *$oi*e-De#ete5 'o5e i! -Do ,o" %a't to go to #i'+e5 #i!t i(#ee'tatio' agai'1
Li'+e5 #i!t i(#ee'tatio'1.I'!ert-.De#ete.Di!(#a,2.E0itE'ter ,o"r *$oi*e24Do ,o" %a't to go to #i'+e5 #i!t i(#ee'tatio'agai'
:
2S
7/25/2019 Data Structure Lab11.PDF
30/70
8. C Progra to *reate a *ir*"#ar !i'g#, #i'+e5 #i!t to(er&or t$e &o##o%i'g
o(eratio' a)I'!ert &ro't )I'!ert Rear *)De#ete &ro't 5)De#ete Rear e)Di!(#a,
#include#includestruct node{int data;struct node Qlin;&;tpedef struct node QB+=;B+= rst6%,last6%;int i,choice,ch161,choice1,ch261,choice2,ch361;void main(){clrscr();while(ch1){printf(Vircular lined list operation*n);printf( 1.Insert*n 2.elete*n 3.ispla*n 0.=it*n);printf(=nter our choice*n);scanf(!d,"choice);switch(choice){case 1/printf(Insert implemenetation*n);
ch261;while(ch2661){printf(1.Insert Jront*n);printf(2.Insert Gear*n);printf(=nter our choice*n);
scanf(!d,"choice1);switch(choice1){case 1/InsertLfront("rst,"last); $rea;case 2/InsertLlast("rst,"last); $rea;default/printf(?ron@ choice*n);&
printf(o ou want to @o to insert implementationa@ain*n);
3%
7/25/2019 Data Structure Lab11.PDF
31/70
scanf(!d,"ch2);&$rea;
case 2/printf(elete implemenetation*n);ch361;while(ch3661)
{printf(1.elete Jront*n);printf(2.elete Gear*n);printf(=nter our choice*n);scanf(!d,"choice2);switch(choice2){case 1/eleteLfront("rst,"last); $rea;case 2/eleteLlast("rst,"last); $rea;default/printf(?ron@ choice*n);&printf(o ou want to @o to delete implementation
a@ain*n);scanf(!d,"ch3);&$rea;
case 3/ispla("rst,"last);$rea;
case 0/eit(%);default/printf(?ron@ choice*n);
$rea;&printf(o ou want to continue*n);scanf(!d,"ch1);&&InsertLfront(B+= Qrst,B+= Qlast)
{B+= newnode;newnode6(B+=)malloc(sieof(B+=));newnode'>lin6newnode;printf(=nter the data*n);scanf(!d,"newnode'>data);if(Qrst66%){Qrst6Qlast6newnode;
return;&
31
7/25/2019 Data Structure Lab11.PDF
32/70
newnode'>lin6Qrst;(Qlast)'>lin6newnode;Qrst6newnode;return;&InsertLlast(B+= Qrst2,B+= Qlast2)
{B+= newnode;newnode6(B+=)malloc(sieof(struct node));newnode'>lin6newnode;printf(=nter the data to $e stored in the node*n);scanf(!d,"newnode'>data);if(Qrst266%){Qrst26Qlast26newnode;return;&(Qlast2)'>lin6newnode;newnode'>lin6Qrst2;Qlast26newnode;return;&eleteLfront(B+= Qrst3,B+= Qlast3){if(Qrst366%){printf(Bo nodes in the list*n);return;&printf(eleted node is !d*n,(Qrst3)'>data);if((Qrst3)'>lin66Qrst3){free(Qrst3);Qrst36Qlast36%;
return;&(Qlast3)'>lin6(Qrst3)'>lin;free(Qrst3);Qrst36(Qlast3)'>lin;return;&eleteLlast(B+= Qrst0,B+= Qlast0){
B+= temp;if(Qrst066%)
32
7/25/2019 Data Structure Lab11.PDF
33/70
{printf(Bo nodes in the list*n);return;&printf(eleted node6!d*n,(Qlast0)'>data);if((Qrst0)'>lin66Qrst0)
{free(Qrst0);Qrst06Qlast06%;return;&temp6Qrst0;while(temp'>linN6Qlast0)temp6temp'>lin;temp'>lin6Qrst0;free(Qlast0);Qlast06temp;return;&ispla(B+= Qrst,B+= Qlast){B+= temp;if(Qrst66%){printf(Bo nodes in the list*n);return;&temp6Qrst;while(temp'>linN6Qrst){printf(!d6>,temp'>data);temp6temp'>lin;&printf(!d ,(Qlast)'>data);
return;&
O=TP=T
Vircular lined list operation1.Insert
2.elete3.ispla0.=it
33
7/25/2019 Data Structure Lab11.PDF
34/70
=nter our choice1Insert implemenetation1.Insert Jront2.Insert Gear=nter our choice1=nter the data
30o ou want to @o to insert implementation a@ain
11.Insert Jront2.Insert Gear=nter our choice2=nter the data to $e stored in the node0o ou want to @o to insert implementation a@ain%
o ou want to continue1Vircular lined list operation1.Insert2.elete3.ispla0.=it=nter our choice2elete implemenetation1.elete Jront2.elete Gear=nter our choice1eleted node is 30o ou want to @o to delete implementation a@ain%o ou want to continue1Vircular lined list operation1.Insert2.elete3.ispla
0.=it=nter our choice30 o ou want to continue%
9. C Progra to *reate a 5o"#, #i'+e5 #i!t to (er&ort$e &o##o%i'g
o(eratio'
a)I'!ert &ro't )I'!ert Rear *)De#ete &ro't 5)De#ete Rear e)Di!(#a,
30
7/25/2019 Data Structure Lab11.PDF
35/70
#include#includestruct node{ int data; struct node Qllin;
struct node Qrlin; &; tpedef struct node QB+=; B+= rst6%; int i,choice,ch161,choice1,ch261,choice2,ch361; B+= InsertLfront(B+= rst); B+= InsertLend(B+= rst); B+= eleteLfront(B+= rst); B+= eleteLend(B+= rst); void main() { clrscr(); while(ch1661) { printf(ou$l lined list operation*n); printf(1.Insert*n); printf(2.elete*n); printf(3.ispla*n); printf(0.=it*n); printf(=nter our choice*n); scanf(!d,"choice); switch(choice) { case 1/printf(Insert implementation*n);
ch261; while(ch2661) { printf(1.Insert front*n);
printf(2.Insert rear*n); printf(=nter our choice*n); scanf(!d,"choice1); switch(choice1) { case 1/rst6InsertLfront(rst);
$rea; case 2/rst6InsertLend(rst);
$rea;
default/printf(?ron@ choice*n); &
3
7/25/2019 Data Structure Lab11.PDF
36/70
printf(o ou want to @o to insert implementationa@ain*n);
scanf(!d,"ch2); & $rea;
case 2/printf(elete implementation*n);
ch361; while(ch3661) { printf(1.elete front*n); printf(2.elete rear*n); printf(=nter our choice*n); scanf(!d,"choice2); switch(choice2) { case 1/rst6eleteLfront(rst);
$rea; case 2/rst6eleteLend(rst);
$rea; default/printf(?ron@ choice*n); & printf(o ou want to @o to delete implementation
a@ain*n); scanf(!d,"ch3); & $rea;
case 3/ispla(rst); $rea;
case 0/eit(%);
default/printf(?ron@ choice*n);$rea; & printf(o ou want to continue*n); scanf(!d,"ch1);
& &
B+= InsertLfront(B+= rst) { B+= newnode; newnode6(B+=)malloc(sieof(B+=)); newnode'>rlin6newnode'>llin6%; printf(=nter the data to $e stored*n); scanf(!d,"newnode'>data);
if(rst66%) return(newnode);
3C
7/25/2019 Data Structure Lab11.PDF
37/70
newnode'>rlin6rst; rst'>llin6newnode; rst6newnode; return(rst); & B+= InsertLend(B+= rst)
{ B+= newnode,temp; newnode6(B+=)malloc(sieof(B+=)); newnode'>rlin6newnode'>llin6%; printf(=nter the data to $e stored in the node*n); scanf(!d,"newnode'>data); if(rst66%) return(newnode); temp6rst; while(temp'>rlinN6%) temp6temp'>rlin; temp'>rlin6newnode; newnode'>llin6temp; return(rst); & B+= eleteLfront(B+= rst) { B+= temp; if(rst66%) { printf(Bo nodes in the list*n); return(rst); & temp6rst; printf(eleted node is !d*n,temp'>data); rst6rst'>rlin; rst'>llin6%; free(temp);
return(rst); & B+= eleteLend(B+= rst) { B+= temp; if(rst66%) { printf(Bo nodes in the list*n); return(rst);
& temp6rst;
3D
7/25/2019 Data Structure Lab11.PDF
38/70
if(temp'>rlin66%) { printf(Bode to $e deleted6!d*n,temp'>data); free(temp); rst6%; return(rst);
& while(temp'>rlinN6%) temp6temp'>rlin; printf(eleted node6!d*n,temp'>data); temp'>llin'>rlin6%; free(temp); return(rst); & ispla(B+= rst) { B+= temp; if(rst66%) { printf(Bo nodes in the list*n); return; & temp6rst; while(tempN6%)
{ printf(!d6>,temp'>data); temp6temp'>rlin; &return;Kou$l lined list operation1.Insert2.elete
3.ispla0.=it=nter our choice1Insert implementation1.Insert front2.Insert rear=nter our choice1
=nter the data to $e stored23
3E
7/25/2019 Data Structure Lab11.PDF
39/70
o ou want to @o to insert implementation [email protected] front2.Insert rear=nter our choice2
=nter the data to $e stored in the node23o ou want to @o to insert implementation a@ain%o ou want to continue1ou$l lined list operation1.Insert2.elete3.ispla0.=it=nter our choice2elete implementation1.elete front2.elete rear=nter our choice1eleted node is 23o ou want to @o to insert implementation a@ain%o ou want to continue%
1:. C< (rogra to *reate a 5o"#, #i'+e5 #i!t to (er&ort$e &o##o%i'g o(eratio'!.a) I'!ert &ro't *) i'!ert at !(*i/e5 (o!tio') 5e#ete &ro't 5)5e#ete at !(*i/e5 (o!tio'
e)5i!(#a,
#include#includestruct node{ int data; struct node Qrlin; struct node Qllin;
&; tpedef struct node QB+=;
3S
7/25/2019 Data Structure Lab11.PDF
40/70
B+= rst6%,last6%; int ch61,choice,ch161,choice1,ch261,choice2; void main() { clrscr(); while(ch661)
{ printf(ou$l [ined [ist implementation *n); printf(1.Insert*n2.elete*n3.ispla*n0.=it*n); printf(=nter ur choice*n); scanf(!d,"choice); switch(choice) { case 1/printf(Insert implementataion*n);
while(ch1661) {printf(1.insert front*n2.insert position*n);printf(=nter ur choice*n);scanf(!d,"choice1);switch(choice1){ case 1/insertLfront("rst,"last); $rea; case 2/insertLpos("rst,"last); $rea; default/printf(wron@ choice*n); & printf(o u want to @o to insert implementation
a@ain*n); scanf(!d,"ch1); & $rea;
case 2/printf(elete implementataion*n);while(ch2661)
{printf(1.elete front*n2.elete position*n);printf(=nter ur choice*n);scanf(!d,"choice2);switch(choice2){ case 1/deleteLfront("rst,"last); $rea; case 2/deleteLpos("rst,"last);
$rea; default/printf(wron@ choice*n);
0%
7/25/2019 Data Structure Lab11.PDF
41/70
& printf(o u want to @o to delete implementation
a@ain*n); scanf(!d,"ch2); & $rea;
case 3/displa("rst,"last);$rea; case 0/eit(%); & printf(o u want to continue*n); scanf(!d,"ch); & & insertLfront(B+= Qrst,B+= Qlast) { B+= newnode; newnode6(B+=)malloc(sieof(struct node)); newnode'>llin6newnode'>rlin6newnode; printf(=nter the data to $e stored*n); scanf(!d,"newnode'>data); if(Qrst66%) { Qrst6newnode; Qlast6newnode; return; & newnode'>rlin6Qrst; (Qrst)'>llin6newnode; (Qlast)'>rlin6newnode; newnode'>llin6Qlast; Qrst6newnode; return; & insertLpos(B+= Qrst,B+= Qlast)
{ B+= newnode,prev,temp; int pos,i; newnode6(B+=)malloc(sieof(struct node)); newnode'>rlin6newnode'>llin6newnode; printf(=nter the data to $e stored*n); scanf(!d,"newnode'>data); printf(=nter the position node to $e stored*n); scanf(!d,"pos);
if(pos661""Qrst66%)
01
7/25/2019 Data Structure Lab11.PDF
42/70
{ Qrst6Qlast6newnode; return; & if(pos661) {
newnode'>rlin6Qrst; (Qrst)'>llin6newnode; newnode'>llin6Qlast; (Qlast)'>rlin6newnode; Qrst6newnode; return; & temp6Qrst; for(i61;illin; prev'>rlin6newnode; newnode'>llin6prev; newnode'>rlin6temp; temp'>llin6newnode; return; & deleteLfront(B+= Qrst,B+= Qlast) { B+= temp; if(Qrst66%)
{ printf(Bo nodes in the list*n); return; & if((Qrst)'>rlin66Qrst) { printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6Qlast6%;
return; &
02
7/25/2019 Data Structure Lab11.PDF
43/70
temp6(Qrst)'>rlin; (Qlast)'>rlin6Qlast; printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6temp; return;
&
deleteLpos(B+= Qrst,B+= Qlast) { B+= temp,prev; int pos,i; if(Qrst66%) { printf(Bo nodes in the list*n); return; & printf(=nter the postion where node to $e deleted*n); scanf(!d,"pos); if(pos661 "" (Qrst)'>rlin66Qrst) { printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6Qlast6%; return; & if(pos661) { temp6(Qrst)'>rlin; printf(Bode to $e deleted6!d*n,(Qrst)'>data); (Qlast)'>rlin6temp; temp'>llin6Qlast; free(Qrst); Qrst6temp;
return; & temp6Qrst; for(i61;i
7/25/2019 Data Structure Lab11.PDF
44/70
prev6temp'>llin; printf(Bode to $e deleted6!d*n,temp'>data); prev'>rlin6temp'>rlin; temp'>rlin'>llin6prev; free(temp); return;
& & displa(B+= Qrst,B+= Qlast) { B+= temp; if(Qrst66%) { printf(Bo nodes in the list*n); return; & temp6Qrst; while(tempN6Qlast) { printf(!d6>,temp'>data); temp6temp'>rlin; & printf(!d6>,(Qlast)'>data); &+utput/'ou$l [ined [ist implementation1.Insert2.elete3.ispla0.=it=nter ur choice1Insert implementataion1.insert front
2.insert position=nter ur choice2=nter the data to $e stored23=nter the position node to $e stored1o u want to @o to insert implementation a@ain1
1.insert front2.insert position
00
7/25/2019 Data Structure Lab11.PDF
45/70
=nter ur choice2=nter the data to $e stored23=nter the position node to $e stored3
invalid posititono u want to @o to insert implementation a@ain%o u want to continue1ou$l [ined [ist implementation1.Insert2.elete3.ispla0.=it=nter ur choice2elete implementataion1.elete front2.elete position=nter ur choice2=nter the postion where node to $e deleted
1Bode to $e deleted623o u want to @o to delete implementation [email protected] front2.elete position=nter ur choice1Bo nodes in the list
o u want to @o to delete implementation a@ain%o u want to continue%
0
7/25/2019 Data Structure Lab11.PDF
46/70
11. C< Progra to *reate a *ir*"#ar 5o"#, #i'+e5 #i!t to(er&or t$e &o##o%i'g
o(eratio'! a)I'!ert &ro't )I'!ert !(e*i/e5 (o!itio' *)De#ete &ro't 5)De#ete !(e*i/e5 (o!itio'
e)Di!(#a,
#include#includestruct node{ int data; struct node Qrlin; struct node Qllin; &;
tpedef struct node QB+=; B+= rst6%,last6%; int ch61,choice,ch161,choice1,ch261,choice2;
0C
7/25/2019 Data Structure Lab11.PDF
47/70
void main() { clrscr(); while(ch661) { printf(ou$l [ined [ist implementation *n);
printf(1.Insert*n2.elete*n3.ispla*n0.=it*n); printf(=nter ur choice*n); scanf(!d,"choice); switch(choice) { case 1/printf(Insert implementataion*n);
while(ch1661) {printf(1.Insert front*n2.Insert position*n);printf(=nter ur choice*n);scanf(!d,"choice1);switch(choice1){ case 1/insertLfront("rst,"last); $rea; case 2/insertLpos("rst,"last); $rea; default/printf(wron@ choice*n); & printf(o u want to @o to insert implementation
a@ain*n); scanf(!d,"ch1); & $rea;
case 2/printf(elete implementataion*n);while(ch2661){printf(1.elete front*n2.elete position*n);
printf(=nter ur choice*n);scanf(!d,"choice2);switch(choice2){ case 1/deleteLfront("rst,"last); $rea; case 2/deleteLpos("rst,"last); $rea; default/printf(wron@ choice*n);
&
0D
7/25/2019 Data Structure Lab11.PDF
48/70
printf(o u want to @o to delete implementationa@ain*n);
scanf(!d,"ch2); & $rea;
case 3/displa("rst,"last);
$rea; case 0/eit(%); & printf(o u want to continue*n); scanf(!d,"ch); & & insertLfront(B+= Qrst,B+= Qlast) { B+= newnode; newnode6(B+=)malloc(sieof(struct node)); newnode'>llin6newnode'>rlin6newnode; printf(=nter the data to $e stored*n); scanf(!d,"newnode'>data); if(Qrst66%) { Qrst6newnode; Qlast6newnode; return; & newnode'>rlin6Qrst; (Qrst)'>llin6newnode; (Qlast)'>rlin6newnode; newnode'>llin6Qlast; Qrst6newnode; return; & insertLpos(B+= Qrst,B+= Qlast) {
B+= newnode,prev,temp; int pos,i; newnode6(B+=)malloc(sieof(struct node)); newnode'>rlin6newnode'>llin6newnode; printf(=nter the data to $e stored*n); scanf(!d,"newnode'>data); printf(=nter the position node to $e stored*n); scanf(!d,"pos);
if(pos661""Qrst66%) {
0E
7/25/2019 Data Structure Lab11.PDF
49/70
Qrst6Qlast6newnode; return; & if(pos661) { newnode'>rlin6Qrst;
(Qrst)'>llin6newnode; newnode'>llin6Qlast; (Qlast)'>rlin6newnode; Qrst6newnode; return; & temp6Qrst; for(i61;illin; prev'>rlin6newnode; newnode'>llin6prev; newnode'>rlin6temp; temp'>llin6newnode; return; & deleteLfront(B+= Qrst,B+= Qlast) { B+= temp; if(Qrst66%) {
printf(Bo nodes in the list*n); return; & if((Qrst)'>rlin66Qrst) { printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6Qlast6%; return;
& temp6(Qrst)'>rlin;
0S
7/25/2019 Data Structure Lab11.PDF
50/70
(Qlast)'>rlin6Qlast; printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6temp; return; &
deleteLpos(B+= Qrst,B+= Qlast) { B+= temp,prev; int pos,i; if(Qrst66%) { printf(Bo nodes in the list*n); return; & printf(=nter the postion where node to $e deleted*n); scanf(!d,"pos); if(pos661 "" (Qrst)'>rlin66Qrst) { printf(Bode to $e deleted6!d*n,(Qrst)'>data); free(Qrst); Qrst6Qlast6%; return; & if(pos661) { temp6(Qrst)'>rlin; printf(Bode to $e deleted6!d*n,(Qrst)'>data); (Qlast)'>rlin6temp; temp'>llin6Qlast; free(Qrst); Qrst6temp; return;
& temp6Qrst; for(i61;illin;
%
7/25/2019 Data Structure Lab11.PDF
51/70
printf(Bode to $e deleted6!d*n,temp'>data); prev'>rlin6temp'>rlin; temp'>rlin'>llin6prev; free(temp); return; &
& displa(B+= Qrst,B+= Qlast) { B+= temp; if(Qrst66%) { printf(Bo nodse in the list*n); return; & temp6Qrst; while(tempN6Qlast) { printf(!d6>,temp'>data); temp6temp'>rlin; & printf(!d6>,(Qlast)'>data); &+utput/'ou$l [ined [ist implementation1.Insert2.elete3.ispla0.=it=nter ur choice1Insert implementataion1.Insert front2.Insert position
=nter ur choice1=nter the data to $e stored30o u want to @o to insert implementation [email protected] front2.Insert position=nter ur choice
1=nter the data to $e stored
1
7/25/2019 Data Structure Lab11.PDF
52/70
23o u want to @o to insert implementation [email protected] front2.Insert position=nter ur choice
2=nter the data to $e stored30=nter the position node to $e stored2o u want to @o to insert implementation a@ain%o u want to continue1ou$l [ined [ist implementation1.Insert2.elete3.ispla0.=it=nter ur choice3236>306>306>o u want to continue1ou$l [ined [ist implementation1.Insert2.elete3.ispla0.=it=nter ur choice2elete implementataion1.elete front2.elete position
=nter ur choice2=nter the postion where node to $e deleted2Bode to $e deleted630o u want to @o to delete implementation a@ain%o u want to continue1
ou$l [ined [ist implementation1.Insert
2
7/25/2019 Data Structure Lab11.PDF
53/70
2.elete3.ispla0.=it=nter ur choice3236>306>o u want to continue
%
1-.CINAR@ TREE
#include#includestruct node{int data;
struct node Qlchild;struct node Qrchild;&;tpedef struct node QB+=;B+= root6%;void inorder(B+= root0);void main(){clrscr();
printf(Vreate tree*n);root6(B+=)malloc(sieof(struct node));printf(=nter the data for root node*n);scanf(!d,"root'>data);create("root);printf(Inorder traversal*n);inorder(root);@etch();&
create(B+= Qroot1){B+= temp,temp1;if(isLlchild("(Qroot1))){(Qroot1)'>lchild6(B+=)malloc(sieof(struct node));temp6(Qroot1)'>lchild;printf(=nter the data for left child*n);scanf(!d,"temp'>data);
create("temp);&
3
7/25/2019 Data Structure Lab11.PDF
54/70
else(Qroot1)'>lchild6%;if(isLrchild("(Qroot1))){(Qroot1)'>rchild6(B+=)malloc(sieof(struct node));temp16(Qroot1)'>rchild;
printf(=nter the data for ri@ht child*n);scanf(!d,"temp1'>data);create("temp1);&else(Qroot1)'>rchild6%;return;&isLlchild(B+= Qroot2){int ch;printf(o ou want to create lchild of(!d),tpe 1 means es;%means no*n,(Qroot2)'>data);scanf(!d,"ch);if(ch661)return(1);elsereturn(%);&isLrchild(B+= Qroot3){int ch;printf(o ou want to create rchild of(!d),tpe 1 means es;%means no*n,(Qroot3)'>data);scanf(!d,"ch);if(ch661)return(1);else
return(%);&void inorder(B+= root0){if(root0N6%){inorder(root0'>lchild);printf(!d6>,root0'>data);inorder(root0'>rchild);
&&
0
7/25/2019 Data Structure Lab11.PDF
55/70
O=TP=TCreate treeE'ter t$e 5ata &or root 'o5e-
Do ,o" %a't to *reate #*$i#5 o&-);t,(e 1 ea'! ,e!: ea'! 'o1E'ter t$e 5ata &or #e&t *$i#524Do ,o" %a't to *reate #*$i#5 o&24);t,(e 1 ea'! ,e!: ea'! 'o1E'ter t$e 5ata &or #e&t *$i#51:Do ,o" %a't to *reate #*$i#5 o&1:);t,(e 1 ea'! ,e!: ea'! 'o:Do ,o" %a't to *reate r*$i#5 o&1:);t,(e 1 ea'! ,e!: ea'! 'o:
Do ,o" %a't to *reate r*$i#5 o&24);t,(e 1 ea'! ,e!: ea'! 'o1E'ter t$e 5ata &or rig$t *$i#5-Do ,o" %a't to *reate #*$i#5 o&-);t,(e 1 ea'! ,e!: ea'! 'o:Do ,o" %a't to *reate r*$i#5 o&-);t,(e 1 ea'! ,e!: ea'! 'o:Do ,o" %a't to *reate r*$i#5 o&-);t,(e 1 ea'! ,e!: ea'! 'o:I'or5er traer!a#
1:24--
7/25/2019 Data Structure Lab11.PDF
56/70
1.CINAR@ TREE AND
PERFORM TREE TRAERSALPREORDER;INORDER AND POSTORDER
#include#includestruct node{
int data;struct node Qlchild;struct node Qrchild;&;tpedef struct node QB+=;B+= root6%;void preorder(B+= root0);void inorder(B+= root);void postorder(B+= rootC);void main(){clrscr();printf(Vreate tree*n);root6(B+=)malloc(sieof(struct node));printf(=nter the data for root node*n);scanf(!d,"root'>data);create("root);printf(reorder traversal*n);preorder(root);printf(*nInorder traversal*n);inorder(root);printf(*nostorder traversal*n);postorder(root);@etch();&create(B+= Qroot1){B+= temp,temp1;
if(isLlchild("(Qroot1))){
C
7/25/2019 Data Structure Lab11.PDF
57/70
(Qroot1)'>lchild6(B+=)malloc(sieof(struct node));temp6(Qroot1)'>lchild;printf(=nter the data for left child*n);scanf(!d,"temp'>data);create("temp);&
else(Qroot1)'>lchild6%;if(isLrchild("(Qroot1))){(Qroot1)'>rchild6(B+=)malloc(sieof(struct node));temp16(Qroot1)'>rchild;printf(=nter the data for ri@ht child*n);scanf(!d,"temp1'>data);create("temp1);&else(Qroot1)'>rchild6%;return;&isLlchild(B+= Qroot2){int ch;printf(o ou want to create lchild of (!d),tpe 1 means es;%means no*n,(Qroot2)'>data);scanf(!d,"ch);if(ch661)return(1);elsereturn(%);&isLrchild(B+= Qroot3){int ch1;
printf(o ou want to create rchild of (!d),tpe 1 meanses;% means no*n,(Qroot3)'>data);scanf(!d,"ch1);if(ch1661)return(1);elsereturn(%);&void preorder(B+= root0)
{if(root0N6%)
D
7/25/2019 Data Structure Lab11.PDF
58/70
{printf(!d6>,root0'>data);preorder(root0'>lchild);preorder(root0'>rchild);&&void inorder(B+= root)
{if(rootN6%){inorder(root'>lchild);printf(!d6>,root'>data);inorder(root'>rchild);&&void postorder(B+= rootC){if(rootCN6%){postorder(rootC'>lchild);postorder(rootC'>rchild);printf(!d6>,rootC'>data);&&O=TP=TrchildN6%) { parent6; succ6'>rchild; while(succ'>lchildN6%) { parent6succ; succ6succ'>lchild; & '>data6succ'>data; 6succ; &
if('>lchildN6%""'>rchild66%){if(parent'>lchild66)parent'>lchild6'>lchild;elseparent'>rchild6'>lchild;free();return;&if('>lchild66% "" '>rchildN6%){if(parent'>lchild66)parent'>lchild6'>rchild;
elseparent'>rchild6'>rchild;free();return; & if('>lchild66% "" '>rchild66%){if(parent'>lchild66)parent'>lchild6%;
elseparent'>rchild6%;
C1
7/25/2019 Data Structure Lab11.PDF
62/70
free();return;&& search(B+= Qroot3,B+= Qpar,B+= Q,int Qfound,int num2) {
B+= Y; Qfound6J:[8=; Qpar6%; Y6Qroot3; while(YN6%) { if(Y'>data66num2) { Qfound6-G=; Q6Y; return; & Qpar6Y; if(num2lchild; else Y6Y'>rchild;&return; & void inorder(B+= root0) {
if(root0N6%) { inorder(root0'>lchild); printf(!d6>,root0'>data); inorder(root0'>rchild);
& &
+utput/'=B-=G -H= B\=G +J B+=8 -+ \= VG=:-=B3=netr the data30=netr the data0
=netr the dataC
C2
7/25/2019 Data Structure Lab11.PDF
63/70
inorder traversal $efore deletion306>06>C6>=nter the node to $e deleted00 to $e deleted is foundinorder traversal after deletion306>C6>
14. CINAR@ TREE ANDEAL=ATE THE POSTFIX
EXPRESSION
#includeC3
7/25/2019 Data Structure Lab11.PDF
64/70
#include#includestruct node{char data;struct node Qlchild;
struct node Qrchild;&;tpedef struct node QB+=;B+= root6%;B+= createLtree(char post42%5);]oat evalLpost(B+= root);void main(){char post42%5;]oat result;clrscr();printf(=nter the post epression*n);scanf(!s,post);root6createLtree(post);result6evalLpost(root);printf(result6!f,result);@etch();&B+= createLtree(char post42%5){B+= temp,stac42%5;char sm$ol;int i,F6%; for(i6%;(sm$ol6post4i5)N6*%;iAA){temp6(B+=)malloc(sieof(struct node));temp'>lchild6temp'>rchild6%;temp'>data6sm$ol;
if(isalnum(sm$ol))stac4FAA56temp;else{temp'>rchild6stac4''F5;temp'>lchild6stac4''F5;stac4FAA56temp;&&return(stac4''F5);
&]oat evalLpost(B+= root)
C0
7/25/2019 Data Structure Lab11.PDF
65/70
{]oat num;switch(root'>data){case A/return evalLpost(root'>lchild)AevalLpost(root'>rchild);case '/return evalLpost(root'>lchild)'evalLpost(root'>rchild);
case Q/return evalLpost(root'>lchild)QevalLpost(root'>rchild);case R/return evalLpost(root'>lchild)RevalLpost(root'>rchild);case O/return pow(evalLpost(root'>lchild),evalLpost(root'>rchild));default /if(isalpha(root'>data))
{ printf(=nter the value of !c*n,root'>data); scanf(!f,"num); return num; & else return(root'>data); &
&O=TP=TE'ter t$e (o!t/0 e0(re!!io'aE'ter t$e a#"e o& a2E'ter t$e a#"e o& re!"#t7.::::::
C
7/25/2019 Data Structure Lab11.PDF
66/70
16.CINAR@ THREADEDTREE
#include#includestruct node
{int data;struct node Qri@ht;struct node Qleft;int G-;&;tpedef struct node QB+=;B+= head6%;B+= create(int item,B+= head);void insertLleft(int item,B+= ptr);void insertLri@ht(int item,B+= ptr);void inorder(B+= head);B+= inorderLsuccessor(B+= ptr);int ch,i,n,item,choice;void main(){clrscr();head6(B+=)malloc(sieof(struct node));head'>ri@ht6head;head'>left6B[[;head'>G-6%;while(1){printf(1.Vreate*n2.Inorder*n3.=it*n);printf(=nter the choice*n);scanf(!d,"ch);switch(ch){
case 1/printf(enter the num$er of nodes to $e created*n);scanf(!d,"n);for(i61;i
7/25/2019 Data Structure Lab11.PDF
67/70
case 3/eit(%);default/printf(?ron@ choice*n);
$rea;&&&B+= create(int item,B+= head){
B+= curptr,ptr;if(head'>left66B[[){insertLleft(item,head);return head;&curptr6head'>left;while(curptrN6head){ptr6curptr;if(itemleftN6B[[)curptr6curptr'>left;else$rea;&else{if(item>curptr'>data){if(curptr'>G-66%)curptr6curptr'>ri@ht;else$rea;&&&if(itemdata "" curptr'>G-661)insertLri@ht(item,ptr);&return head;
&void insertLleft(int item,B+= ptr)
CD
7/25/2019 Data Structure Lab11.PDF
68/70
{B+= temp,newnode;newnode6(B+=)malloc(sieof(struct node));newnode'>left6B[[;newnode'>data6item;ptr'>left6newnode;
newnode'>ri@ht6ptr;newnode'>G-61;&void insertLri@ht(int item,B+= ptr){B+= temp,newnode;newnode6(B+=)malloc(sieof(struct node));newnode'>left6B[[;newnode'>data6item;temp6ptr'>ri@ht;ptr'>ri@ht6newnode;ptr'>G-6%;newnode'>ri@ht6temp;newnode'>G-61;&void inorder(B+= head){B+= temp;if(head'>left66B[[){printf(Bo nodes in the list*n);return;&temp6head;while(1){temp6inorderLsuccessor(temp);if(temp66head)
return;printf(!d*n,temp'>data);&&B+= inorderLsuccessor(B+= ptr){B+= temp;temp6ptr'>ri@ht;if(ptr'>G-661)return temp;
while(temp'>leftN6B[[)temp6temp'>left;
CE
7/25/2019 Data Structure Lab11.PDF
69/70
return(temp);&
+utput/'1.Vreate2.Inorder
3.=it=nter the choice1enter the num$er of nodes to $e created3=nter the 1 data30=nter the 2 data0=nter the 3 data0D1.Vreate2.Inorder3.=it=nter the choice23000D1.Vreate2.Inorder3.=it=nter the choice3
CS
7/25/2019 Data Structure Lab11.PDF
70/70