Vous êtes sur la page 1sur 62

Polynomial Addition:

#include<stdio.h> #include<conio.h> #include<malloc.h> struct link { int co; int exp; struct link *next; }; struct link *p1=NULL;*p =NULL;*p!=NULL; "oid create#struct link *node$ { char ch; do { print%#&'n(nter the )oe%%.*&$; scan%#&+d&,-node.>co$; print%#&'n(nter the exponent*&$; scan%#&+d&,-node.>exp$; node.>next=#struct link*$malloc#si/eo%#struct link$$; node=node.>next; node.>next=NULL; print%#&)ontinue#01N$&$; ch=2etch#$; }3hile#ch==454 66 ch==404$; } "oid sho3#struct link *node$ { 3hile#node.>next 7= NULL$ { print%#&+d x8+d&,node.>co,node.>exp$; node=node.>next; i%#node.>next 7= NULL$ print%#&9&$; } } "oid pol5add#struct link *p1,struct link *p ,struct link *p!$ { 3hile#p1.>next -- p .>next$ { i%#p1.>exp > p .>exp$ { p!.>exp=p1.>exp; p!.>co=p1.>co;

p1=p1.>next; } else i%#p1.>exp < p .>exp$ { p!.>exp=p .>exp; p!.>co=p .>co; p =p .>next; } else { p!.>exp=p1.>exp; p!.>co=p1.>co9p .>co; p1=p1.>next; p =p .>next; } p!.>next=#struct link *$malloc#si/eo%#struct link$$; p!=p!.>next; p!.>next=NULL; } 3hile#p1.>next 66 p .>next$ { i%#p1.>next$ { p!.>exp=p1.>exp; p!.>co=p1.>co; p1=p1.>next; } i%#p .>next$ { p!.>exp=p .>exp; p!.>co=p .>co; p =p .>next; } p!.>next=#struct link *$malloc#si/eo%#struct link$$; p!=p!.>next; p!.>next=NULL; } } "oid main#$ { char ch; do { p1=#struct link *$malloc#si/eo%#struct link$$; p =#struct link *$malloc#si/eo%#struct link$$; p!=#struct link *$malloc#si/eo%#struct link$$;

print%#&'n'n(nter the %irst pol5nomial&$; create#p1$; print%#&'n'n'n(nter the second pol5nomial&$; create#p $; print%#&'n:irst Num;er* &$; sho3#p1$; print%#&'n<econd Num;er* &$; sho3#p $; pol5add#p1,p ,p!$; print%#&'n =dded pol5nomial is&$; sho3#p!$; print%#&'n =dd more num;er...&$; ch=2etch#$; }3hile#ch==454 66 ch==404$; 2etch#$; }

OUTPUT: (nter the %irst pol5nomial (nter the )oe%%.* (nter the exponent*! )ontinue#01N$ (nter the )oe%%.*! (nter the exponent* )ontinue#01N$ (nter the second pol5nomial (nter the )oe%%.*> (nter the exponent*! )ontinue#01N$ (nter the )oe%%.* (nter the exponent* )ontinue#01N$ (nter the )oe%%.*> (nter the exponent*1 )ontinue#01N$ :irst Num;er* x8!9! x8 <econd Num;er* > x8!9 x8 9> x81 =dded pol5nomial is? x8!9@ x8 9> x81 =dd more num;er...

IMPLEMENTATION OF SINGLY LINKED LIST #include<stdio.h> #include<conio.h> #include<process.h> #include<malloc.h> #include<stdli;.h> t5pede% struct list { int rno; char nameA BC; struct list *link; }node; node *2etnode#$; "oid readnode#node *ne3$; "oid createlist#node **headptr$; "oid insert%irst#node **headptr$; "oid insertlast#node **headptr$; "oid insertmiddle#node **headptr$; "oid releasenode#node *delnode$; "oid del%irst#node **headptr$; "oid dellast#node **headptr$; "oid delmiddle#node **headptr$; "oid modi%5node#node **headptr$; "oid "ie3list#node *head$; "oid countnode#node *head$; "oid main#$ { node *head=NULL; int ch,count; char c; clrscr#$; print%#&'n D(NU 'n&$; print%#&'n 1. )E(=F( &$; print%#&'n .Gnsert %irst&$; print%#&'n !.Gnsert last&$; print%#&'n >.Gnsert Diddle&$; print%#&'n @.Helete %irst&$; print%#&'n ?.Helete last&$; print%#&'n I.Helete Diddle&$; print%#&'n J.Kie3 list &$; print%#&'n L.)ount list &$; print%#&'n 1B.Dodi%5 Node &$; print%#&'n B.(xit &$; do {

print%#&(nter the )hoice&$; scan%#&+d&,-ch$; s3itch#ch$ { case 1* createlist#-head$; ;reak; case * insert%irst#-head$; ;reak; case !* insertlast#-head$; ;reak; case >* insertmiddle#-head$; ;reak; case @* del%irst#-head$; ;reak; case ?* dellast#-head$; ;reak; case I* delmiddle#-head$; ;reak; case J* "ie3list#head$; ;reak; case L* countnode#head$; ;reak; case 1B* modi%5node#-head$; ;reak; case B* exit#B$; ;reak; } print%#&'nHo 5ou 3ant to continue or notM&$; scan%#&+s&,-c$; }3hile#c==454 66 c==404$; 2etch#$; } node *2etnode#$ { node *ne3; ne3=#node*$malloc#si/eo%#node$$; return#ne3$; } "oid readnode#node *ne3$ { print%#&'n (nter Eoll no., Name&$; scan%#&+d +s&,-ne3.>rno,-ne3.>name$; ne3.>link=NULL; } "oid createlist#node **headptr$ {

node *head=NULL; node *ne3,*last; char ch; do { ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { head=ne3; last=head; } else { last.>link=ne3; last=last.>link; } print%#&Ho 5ou 3ant to addM&$; scan%#&+s&,-ch$; }3hile#ch==45466ch==404$; *headptr=head; } "oid insert%irst#node **headptr$ { node *head=*headptr; node *ne3; ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { print%#&List is empt5&$; head=ne3; } else { ne3.>link=head; head=ne3; } *headptr=head; } "oid insertlast#node **headptr$ { node *head,*ne3,*last; head=*headptr; ne3=2etnode#$; readnode#ne3$;

i%#head==NULL$ { print%#&List is empt5&$; head=ne3; } else { last=head; 3hile#last.>link 7= NULL$ { last=last.>link; } last.>link=ne3; } *headptr=head; } "oid insertmiddle#node **headptr$ { int rno; node *head,*ne3,*last; head=*headptr; ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { print%#&'n List is empt5&$; head=ne3; return; } else { print%#&'n(nter the roll no. a%ter 3hich the insertion is to ;e made&$; scan%#&+d&,-rno$; last=head; 3hile#last.>link7=NULL$ { i%#last.>rno==rno$ { ne3.>link=last.>link; last.>link=ne3; return; } else last=last.>link; } print%#&'nNre"ious node not %ound&$;

} *headptr=head; } "oid releasenode#node *delnode$ { %ree#delnode$; } "oid del%irst#node **headptr$ { node *head,*delnode; head=*headptr; i%#head==NULL$ { print%#&'n Fhe list is empt5&$; return; } delnode=head; head=head.>link; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; } "oid dellast#node **headptr$ { node *head,*delnode,*last,*pre"; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; } else i%#head.>link==NULL$ { delnode=head; head=NULL; } else { last=head; 3hile#last.>link7=NULL$ { pre"=last; last=last.>link; } delnode=last;

pre".>link=NULL; } print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; } "oid delmiddle#node **headptr$ { int rno; node *head,*delnode,*last,*pre"; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; } print%#&'n(nter the roll no. %or the node to delete&$; scan%#&+d&,-rno$; i%#head.>rno==rno$ { delnode=head; head=head.>link; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; return; } last=head.>link; pre"=head; 3hile#last7=NULL$ { i%#last.>rno==rno$ { delnode=last; pre".>link=last.>link; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; return; } else { pre"=last;

last=last.>link; } } print%#&'nHelnode is not present&$; *headptr=head; } "oid modi%5node#node **headptr$ { int rno; node *head,*last; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; } print%#&'n(nter the roll no. %or modi%ication&$; scan%#&+d&,-rno$; last=head; 3hile#last7=NULL$ { i%#last.>rno==rno$ { print%#&'n(nter the roll no&$; scan%#&+d&,-last.>rno$; print%#&'n(nter the name&$; scan%#&+s&,-last.>name$; *headptr=head; return; } else last=last.>link; } print%#&'nDodi%5 node is not %ound&$; *headptr=head; } "oid "ie3list#node *head$ { i%#head==NULL$ { print%#&'nList is empt5&$; return; } 3hile#head7=NULL$ { print%#&'n Eoll no=+d , Name= +s &,head.>rno,head.>name$;

head=head.>link; } } "oid countnode#node *head$ { int count=B; i%#head==NULL$ { print%#&'nList is empt5&$; return; } 3hile#head.>link7=NULL$ { count99; head=head.>link; } print%#&'nFhe no. o% nodes in the list is +d&,count$; }

OUTPUT D(NU 1. )E(=F( .Gnsert %irst !.Gnsert last >.Gnsert Diddle @.Helete %irst ?.Helete last I.Helete Diddle J.Kie3 list L.)ount list 1B.Dodi%5 Node B.(xit (nter the )hoice1 (nter Eoll no., Name1 E=O Ho 5ou 3ant to addM0 (nter Eoll no., Name E=D Ho 5ou 3ant to addMN Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoice (nter Eoll no., Name! =O=0 Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=! , Name= =O=0 Eoll no=1 , Name= E=O Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoice! (nter Eoll no., Name> P=LE=O Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=! , Name= =O=0 Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=> , Name= P=LE=O Ho 5ou 3ant to continue or notM0 (nter the )hoice> (nter Eoll no., Name@ QRSU (nter the roll no. a%ter 3hich the insertion is to ;e made

Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=! , Name= =O=0 Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=@ , Name= QRSU Eoll no=> , Name= P=LE=O Ho 5ou 3ant to continue or notM0 (nter the )hoice@ Heleted Hata is Eoll no=! , Name= =O=0 Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=@ , Name= QRSU Eoll no=> , Name= P=LU Ho 5ou 3ant to continue or notM5 (nter the )hoice? Heleted Hata is Eoll no=> , Name= P=LE=O Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=@ , Name= QRSU Ho 5ou 3ant to continue or notM0 (nter the )hoiceI (nter the roll no. %or the node to delete@ Heleted Hata is Eoll no=@ , Name= QRSU Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoiceL Fhe no. o% nodes in the list is Ho 5ou 3ant to continue or notM0 (nter the )hoice1B (nter the roll no. %or modi%ication (nter the roll no@ (nter the nameL=E= Ho 5ou 3ant to continue or notM0 (nter the choice J Eoll no=1 , Name= E=O Eoll no=@ , Name= L=E= Ho 5ou 3ant to continue or notMN.

IMPLEMENTATION OF DOUBLY LINKED LIST #include<stdio.h> #include<conio.h> #include<process.h> #include<malloc.h> #include<stdli;.h> t5pede% struct list { int rno; char nameA BC; struct list *next,*pre"; }node; node *2etnode#$; "oid readnode#node *ne3$; "oid createlist#node **headptr$; "oid insert%irst#node **headptr$; "oid insertlast#node **headptr$; "oid insertmiddle#node **headptr$; "oid releasenode#node *delnode$; "oid del%irst#node **headptr$; "oid dellast#node **headptr$; "oid delmiddle#node **headptr$; "oid modi%5node#node **headptr$; "oid "ie3list#node *head$; "oid countnode#node *head$; "oid main#$ { node *head=NULL; int ch,count; char c; clrscr#$; print%#&'n D(NU 'n&$; print%#&'n 1. )E(=F( &$; print%#&'n .Gnsert %irst&$; print%#&'n !.Gnsert last&$; print%#&'n >.Gnsert Diddle&$; print%#&'n @.Helete %irst&$; print%#&'n ?.Helete last&$; print%#&'n I.Helete Diddle&$; print%#&'n J.Kie3 list &$; print%#&'n L.)ount list &$; print%#&'n 1B.Dodi%5 Node &$; print%#&'n B.(xit &$; do {

print%#&'n(nter the )hoice&$; scan%#&+d&,-ch$; s3itch#ch$ { case 1* createlist#-head$; ;reak; case * insert%irst#-head$; ;reak; case !* insertlast#-head$; ;reak; case >* insertmiddle#-head$; ;reak; case @* del%irst#-head$; ;reak; case ?* dellast#-head$; ;reak; case I* delmiddle#-head$; ;reak; case J* "ie3list#head$; ;reak; case L* countnode#head$; ;reak; case 1B* modi%5node#-head$; ;reak; case B* exit#B$; ;reak; } print%#&'nHo 5ou 3ant to continue or notM&$; scan%#&+s&,-c$; }3hile#c==454 66 c==404$; 2etch#$; } node *2etnode#$ { node *ne3; ne3=#node*$malloc#si/eo%#node$$; return#ne3$; } "oid readnode#node *ne3$ { print%#&'n (nter Eoll no., Name&$; scan%#&+d +s&,-ne3.>rno,-ne3.>name$; ne3.>next=NULL; ne3.>pre"=NULL; } "oid createlist#node **headptr$

{ node *head=NULL; node *ne3,*last; char ch; head=*headptr; do { ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { head=ne3; last=head; } else { ne3.>pre"=last; last.>next=ne3; last=last.>next; } print%#&Ho 5ou 3ant to addM&$; scan%#&+s&,-ch$; }3hile#ch==45466ch==404$; 11print%#&'n&$; 11print%#&+d +s&,head.>rno,head.>name$; *headptr=head; } "oid insert%irst#node **headptr$ { node *head=*headptr; node *ne3; ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { print%#&List is empt5&$; head=ne3; } else { ne3.>next=head; head.>pre"=ne3; head=ne3; } *headptr=head; }

"oid insertlast#node **headptr$ { node *head,*ne3,*last; head=*headptr; ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { print%#&List is empt5&$; head=ne3; } else { last=head; 3hile#last.>next 7= NULL$ { last=last.>next; } last.>next=ne3; ne3.>pre"=last; } *headptr=head; } "oid insertmiddle#node **headptr$ { int rno; node *head,*ne3,*last,*pre",*next; head=*headptr; ne3=2etnode#$; readnode#ne3$; i%#head==NULL$ { print%#&'n List is empt5&$; head=ne3; return; } else { print%#&'n(nter the roll no. a%ter 3hich the insertion is to ;e made&$; scan%#&+d&,-rno$; last=head; 3hile#last.>next7=NULL$ { i%#last.>rno==rno$ { next=last.>next;

ne3.>next=next; ne3.>pre"=last; last.>next=ne3; i%#next7=NULL$ { next.>pre"=ne3; return; } } else last=last.>next; } print%#&'nNre"ious node not %ound&$; } *headptr=head; } "oid releasenode#node *delnode$ { %ree#delnode$; } "oid del%irst#node **headptr$ { node *head,*delnode; head=*headptr; i%#head==NULL$ { print%#&'n Fhe list is empt5&$; return; } delnode=head; head=head.>next; head.>pre"=NULL; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; } "oid dellast#node **headptr$ { node *head,*delnode,*last,*pre"; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; }

else i%#head.>next==NULL$ { delnode=head; head=NULL; } else { last=head; 3hile#last.>next7=NULL$ { pre"=last; last=last.>next; } delnode=last; pre"=last.>pre"; pre".>next=NULL; } print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; } "oid delmiddle#node **headptr$ { int rno; node *head,*delnode,*last,*pre",*next; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; } print%#&'n(nter the roll no. %or the node to delete&$; scan%#&+d&,-rno$; i%#head.>rno==rno$ { delnode=head; head=head.>next; head.>pre"=NULL; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; return; } last=head.>next;

3hile#last7=NULL$ { i%#last.>rno==rno$ { delnode=last; pre"=last.>pre"; next=last.>next; pre".>next=next; i%#next7=NULL$ next.>pre"=pre"; print%#&'n Heleted Hata is &$; print%#&Eoll no=+d , Name= +s&,delnode.>rno,delnode.>name$; releasenode#delnode$; *headptr=head; return; } else { last=last.>next; } } print%#&'nHelnode is not present&$; *headptr=head; } "oid modi%5node#node **headptr$ { int rno; node *head,*last,*next; head=*headptr; i%#head==NULL$ { print%#&'nList is (mpt5&$; return; } print%#&'n(nter the roll no. %or modi%ication&$; scan%#&+d&,-rno$; last=head; 3hile#last7=NULL$ { i%#last.>rno==rno$ { print%#&'n(nter the roll no&$; scan%#&+d&,-last.>rno$; print%#&'n(nter the name&$; scan%#&+s&,-last.>name$; *headptr=head;

return; } else last=last.>next; } print%#&'nDodi%5 node is not %ound&$; *headptr=head; } "oid "ie3list#node *head$ { i%#head==NULL$ { print%#&'nList is empt5&$; return; } 3hile#head7=NULL$ { print%#&'n Eoll no=+d , Name= +s &,head.>rno,head.>name$; head=head.>next; } } "oid countnode#node *head$ { int count=B; i%#head==NULL$ { print%#&'nList is empt5&$; return; } 3hile#head7=NULL$ { count99; head=head.>next; } print%#&'nFhe no. o% nodes in the list is +d&,count$; }

OUTPUT D(NU 1. )E(=F( .Gnsert %irst !.Gnsert last >.Gnsert Diddle @.Helete %irst ?.Helete last I.Helete Diddle J.Kie3 list L.)ount list 1B.Dodi%5 Node B.(xit (nter the )hoice1 (nter Eoll no., Name1 E=O Ho 5ou 3ant to addM0 (nter Eoll no., Name E=D Ho 5ou 3ant to addMN Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoice (nter Eoll no., Name! <EG Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=! , Name= <EG Eoll no=1 , Name= E=O Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoice! (nter Eoll no., Name> P=LU Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=! , Name= <EG Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=> , Name= P=LU Ho 5ou 3ant to continue or notM0 (nter the )hoice> (nter Eoll no., Name? QRSU (nter the roll no. a%ter 3hich the insertion is to ;e made Ho 5ou 3ant to continue or notM0

(nter the )hoiceJ Eoll no=! , Name= <EG Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=? , Name= QRSU Eoll no=> , Name= P=LU Ho 5ou 3ant to continue or notM0 (nter the )hoice@ Heleted Hata is Eoll no=! , Name= <EG Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=? , Name= QRSU Eoll no=> , Name= P=LU Ho 5ou 3ant to continue or notM5 (nter the )hoice? Heleted Hata is Eoll no=> , Name= P=LU Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no= , Name= E=D Eoll no=? , Name= QRSU Ho 5ou 3ant to continue or notM0 (nter the )hoiceI (nter the roll no. %or the node to delete Heleted Hata is Eoll no= , Name= E=D Ho 5ou 3ant to continue or notM0 (nter the )hoiceJ Eoll no=1 , Name= E=O Eoll no=? , Name= QRSU Ho 5ou 3ant to continue or notM0 (nter the )hoiceL Fhe no. o% nodes in the list is Ho 5ou 3ant to continue or notM0 (nter the )hoice1B (nter the roll no. %or modi%ication? (nter the roll no@ (nter the nameL=E= Ho 5ou 3ant to continue or notM0 (nter the choice J Eoll no=1 , Name= E=O Eoll no=@ , Name= L=E= Ho 5ou 3ant to continue or notM0. (nter the choice B.

CONVERSION OF INFI TO POSTFI #include<stdio.h> #include<conio.h> #include<ct5pe.h> #include<strin2.h> #de%ine D=T L t5pede% struct node { char data; struct node *next; }stack; int push#char$; int pop#char *$; stack *2etnode#$; "oid releasenode#stack *$; "oid intopost#charAC,charAC$; int indexprior#char pACA C,char data$; stack *topstk=NULL; char ipAD=TCA C={{4#4,>},{4$4,B},{4'B4,B},{494,1},{4.4,1},{4*4, },{414,!},{4+4, },{484,!}}; char spAD=TCA C={{4#4,B},{4$4,.1},{4'B4,B},{494,1},{4.4,1},{4*4, },{414,!},{4+4, },{484,!}}; "oid main#$ { char instrA BC,poststrA BC; clrscr#$; print%#&'n(nter GN:GT expression* &$; scan%#&+s&,instr$; intopost#instr,poststr$; print%#&'nFhe NR<F:GT expression is +s&,poststr$; 2etch#$; } int push#char "alue$ { extern stack *topstr; stack *ne3; ne3=2etnode#$; i%#ne3==NULL$ return .1; ne3.>data="alue; ne3.>next=topstk; topstk=ne3; return B; } int pop#char *"alue$ { extern stack *topstk;

stack *temp; i%#topstk==NULL$ return .1; temp=topstk; topstk=topstk.>next; *"alue=temp.>data; releasenode#temp$; return B; } stack *2etnode#$ { return #stack*$malloc#si/eo%#stack$$; } "oid releasenode#stack *ne3node$ { %ree#ne3node$; } "oid intopost#char instrAC,char poststrAC$ { char ch,item; int i=B,st=B,spr,ipr; push#4'B4$; 3hile##ch=instrAst99C$7=NULL$ { i%#tolo3er#ch$>=4a4 -- tolo3er#ch$<=4/4$ poststrAi99C=ch; else i%#ch==4#4$ push#ch$; else i%#ch==4$4$ { pop#-item$; 3hile#item7=4#4$ {poststrAi99C=item; pop#-item$; } } else { pop#-item$; spr=indexprior#sp,item$; ipr=indexprior#ip,ch$; 3hile#spAsprCA1C>=ipAiprCA1C$ { poststrAi99C=item; pop#-item$; spr=indexprior#sp,item$;

} push#item$; push#ch$; } } 3hile#7pop#-item$$ poststrAi99C=item; } int indexprior#char pACA C,char data$ { int ind; %or#ind=B;ind<D=T;ind99$ { i%#pAindCABC==data$ return ind; } return ind; }

OUTPUT (nter GN:GT expression* ##=.#P9)$*H$9#(9:$$ Fhe NR<F:GT expression is =P)9H*.(:99

IMPLEMNTATION OF DOUBLE ENDED !UEUE #include<stdio.h> #include<conio.h> #include<malloc.h> #include<stdli;.h> #de%ine <GU( @ "oid displa5#$; int VueueA<GU(C,%ront=.1,rear=.1; int empt5#$; int %ull#$; int enVueue%ront#int$; int enVueuerear#int$; int deVueue%ront#int *"alue$; int deVueuerear#int *"alue$; int si/e#$; "oid "ie3#$; "oid main#$ { int status,choice,data; clrscr#$; displa5#$; 3hile#1$ { print%#&'n (nter 5our choice... &$; print%#&'n&$; scan%#&+d&,-choice$; s3itch#choice$ { case B* displa5#$; ;reak; case 1* print%#&'n (nter the (lement &$; %%lush#stdin$; scan%#&+d&,-data$; status=enVueue%ront#data$; i%#status==.1$ print%#&'n HeVueue o"er%lo3 on enVueue at %ront&$; ;reak; case * print%#&'n (nter the (lement &$; %%lush#stdin$; scan%#&+d&,-data$; status=enVueuerear#data$; i%#status==.1$ print%#&'n HeVueue o"er%lo3 on enVueue at rear&$; ;reak; case !* status=deVueue%ront#-data$;

i%#status==.1$ print%#&'n HeVueue under%lo3 on enVueue at %ront&$; else print%#&'n Fhe deVueue "alue is +d&,data$; ;reak; case >* status=deVueuerear#-data$; i%#status==.1$ print%#&'n HeVueue under%lo3 on enVueue at rear&$; else print%#&'n Fhe deVueue "alue is +d&,data$; ;reak; case @* print%#&'n No. o% elements in deVueue id +d&,si/e#$$; ;reak; case ?* "ie3#$; ;reak; de%ault* print%#&'n (nd o% Eun&$; exit#B$; } } } "oid displa5#$ { print%#&'n HeVueue usin2 arra5 &$; print%#&'n 't B. Kie3 menu &$; print%#&'n 't 1. (nVueue at %ront &$; print%#&'n 't . (nVueue at rear &$; print%#&'n 't !. HeVueue at %ront &$; print%#&'n 't >. HeVueue at rear &$; print%#&'n 't @. si/e o% Vueue &$; print%#&'n 't ?. Kie3 &$; print%#&'n 't I. (xit &$; } int empt5#$ { extern int VueueAC,%ront,rear; i%#%ront==.1 -- rear==.1$ return 1; else return B; } int %ull#$ { extern int VueueAC,%ront,rear; i%#rear==#<GU(.1$$ return .1; else

return B; } int enVueue%ront#int "alue$ { extern int VueueAC,rear,%ront; i%#empt5#$$ %ront=rear=B; else i%#%ull#$$ return .1; else %ront=%ront.1; VueueA%rontC="alue; return B; } int enVueuerear#int "alue$ { extern int VueueAC,rear,%ront; i%#empt5#$$ %ront=rear=B; else i%#%ull#$$ return .1; else rear=rear91; VueueArearC="alue; return B; } int deVueue%ront#int *"alue$ { extern int VueueAC,rear,%ront; i%#empt5#$$ return .1; *"alue=VueueA%rontC; i%#%ront==rear$ %ront=rear=.1; else %ront=%ront91; return B; } int deVueuerear#int *"alue$ { extern int VueueAC,rear,%ront; i%#empt5#$$ return .1; *"alue=VueueArearC; i%#%ront==rear$ %ront=rear=.1;

else rear=rear.1; return B; } int si/e#$ { extern int VueueAC,%ront,rear; i%#empt5#$$ return B; return#rear.%ront91$; } "oid "ie3#$ { extern int VueueAC,%ront,rear; int %; i%#empt5#$$ { print%#&'n HeVueue is empt5&$; return B; } print%#&'n )ontent o% the HeVueue... 'n :ERNF.>&$; %or#%=%ront;%7=rear;%=%91$ print%#&+d &,VueueA%C$; print%#&+d.>E(=E&,VueueA%C$; i% #%ull#$$ print%#&'n HeVueue is %ull&$; }

OUTPUT HeVueue usin2 arra5 B. Kie3 menu 1. (nVueue at %ront . (nVueue at rear !. HeVueue at %ront >. HeVueue at rear @. si/e o% Vueue ?. Kie3 I. (xit (nter 5our choice... 1 (nter the (lement (nter 5our choice... ? )ontent o% the HeVueue... :ERNF.> .>E(=E (nter 5our choice... 1 (nter the (lement @ (nter 5our choice... ? )ontent o% the HeVueue... :ERNF.>@ .>E(=E (nter 5our choice... (nter the (lement > (nter 5our choice... ? )ontent o% the HeVueue... :ERNF.>@ >.>E(=E (nter 5our choice... (nter the (lement J

(nter 5our choice... ? )ontent o% the HeVueue... :ERNF.>@ > J.>E(=E (nter 5our choice... ! Fhe deVueue "alue is @ (nter 5our choice... ? )ontent o% the HeVueue... :ERNF.> > J.>E(=E (nter 5our choice... > Fhe deVueue "alue is J (nter 5our choice... ? )ontent o% the HeVueue... :ERNF.> >.>E(=E (nter 5our choice... B HeVueue usin2 arra5 B. Kie3 menu 1. (nVueue at %ront . (nVueue at rear !. HeVueue at %ront >. HeVueue at rear @. si/e o% Vueue ?. Kie3 I. (xit (nter 5our choice... @ No. o% elements in deVueue id (nter 5our choice...

IMPLEMENTATION OF TREE TRAVERSAL #include<stdio.h> #include<conio.h> #include<stdli;.h> #de%ine <GU( B t5pede% struct node { char data; struct node *le%t; struct node *ri2ht; };tree; ;tree *stackA<GU(C; int top; "oid main#$ { ;tree *root; char expAJBC; ;tree *create#char expAJBC$; "oid inorder#;tree *root$; "oid preorder#;tree *root$; "oid postorder#;tree *root$; clrscr#$; print%#&'n(nter the post%ix (xpression...'n&$; scan%#&+s&,-exp$; top=.1; root=create#exp$; print%#&'n 't Fhe tree is created...'n'n'n&$; print%#&'nFhe inorder tra"ersal is....'n&$; inorder#root$; print%#&'n'n'nFhe preorder tra"ersal is....'n&$; preorder#root$; print%#&'n'n'nFhe postorder tra"ersal is....'n&$; postorder#root$; 2etch#$; } ;tree *create#char expAC$ { ;tree *temp; int pos; char ch; "oid push#;tree *$; ;tree *pop#$; pos=B; ch=expAposC; 3hile#ch7=4'B4$

{ temp=#;tree *$malloc#si/eo%#;tree$$; temp.>le%t=temp.>ri2ht=NULL; temp.>data=ch; i%#isalpha#ch$$ push#temp$; else i%#ch==49466ch==4.466ch==4*466ch==414$ { temp.>ri2ht=pop#$; temp.>le%t=pop#$; push#temp$; } else print%#&'t Gn"alid )haracter (xpression'n&$; pos99; ch=expAposC; } temp=pop#$; return#temp$; } "oid push#;tree *node$ { i%#top91>=<GU($ print%#&'t (EERE * <tack is :ULL....'n&$; top99; stackAtopC=node; } ;tree *pop#$ { ;tree *node; i% #top==.1$ print%#&'n (EERE * <tack is (DNF0....'n&$; node=stackAtopC; top..; return #node$; } "oid inorder#;tree *root$ { ;tree *temp; temp=root; i%#temp7=NULL$ { inorder#temp.>le%t$; print%#&+c&,temp.>data$; inorder#temp.>ri2ht$; }

} "oid preorder#;tree *root$ { ;tree *temp; temp=root; i%#temp7=NULL$ { print%#&+c&,temp.>data$; preorder#temp.>le%t$; preorder#temp.>ri2ht$; } } "oid postorder#;tree *root$ { ;tree *temp; temp=root; i%#temp7=NULL$ { postorder#temp.>le%t$; postorder#temp.>ri2ht$; print%#&+c&,temp.>data$; } }

OUTPUT: (nter the post%ix (xpression... a;c9d*.e%99 Fhe tree is created...

Fhe inorder tra"ersal is.... a.;9c*d9e9% Fhe preorder tra"ersal is.... 9.a*9;cd9e% Fhe postorder tra"ersal is.... a;c9d*.e%99

IMPLEMENTATION OF BINARY SEARC" TREE #include<stdio.h> #include<conio.h> #include<stdli;.h> #de%ine NULL B t5pede% struct tree *node; node insert#int,node t$; "oid %ind#node t,int x$; node %indmin#node t$; node %indmax#node t$; int del#node t,int x$; "oid displa5#node t$; struct tree { int data; struct tree *ri2ht,*le%t; }*root; "oid main#$ { node t=NULL; int data,s,i=B,n,x,ch; char c; clrscr#$; print%#&'n enter the no o% elements in tree* 'n&$; scan%#&+d&,-n$; print%#&'nelements are*'n&$; 3hile#i<n$ { scan%#&+d&,-data$; t=insert#data,t$; i99; } print%#&1.%ind 'n .%indmin 'n!.%indmax 'n>.displa5 'n@.delete 'n?.exit&$; do { print%#&'nenter ur choice* &$; scan%#&+d&,-ch$; s3itch#ch$ { case 1* print%#&'nenter the element search 'n*&$; scan%#&+d&,-s$; %ind#t,s$; ;reak; case * %indmin#t$; ;reak;

case !* %indmax#t$; ;reak; case >*print%#&'nelements dispal5ed in inorder %ormat'n*&$; displa5#t$; ;reak; case @*print%#&'nenter the element to ;e deleted 'n&$; scan%#&+d&,-s$; del#t,s$; ;reak; de%ault*print%#&'nexit&$; exit#B$; } }3hile#ch<L$; 2etch#$; } node insert#int x,node t$ { struct tree *ne3node; ne3node=malloc#si/eo%#struct tree$$; i%#ne3node==NULL$ print%#&out o% space'n&$; else { i%#t==NULL$ { ne3node.>data=x; ne3node.>le%t=NULL; ne3node.>ri2ht=NULL; t=ne3node; } else { i%#x<t.>data$ t.>le%t=insert#x,t.>le%t$; else t.>ri2ht=insert#x,t.>ri2ht$; } }return t; } "oid %ind#node t,int x$ { i%#t==NULL$ print%#&'nsearch element not %ound&$; else { i%#t.>data==x$

print%#&'nsearch element +d is %ound&,x$; else i%#x<t.>data$ %ind#t.>le%t,x$; else %ind#t.>ri2ht,x$; } } node %indmin#node t$ { i%#t7=NULL$ { i%#t.>le%t==NULL$ { print%#&'n the minimum element in tree is+d&,t.>data$; return t; } else %indmin#t.>le%t$; } return t; } node %indmax#node t$ { i%#t7=NULL$ { i%#t.>ri2ht==NULL$ print%#&'n the max element in tree is +d&,t.>data$; else %indmax#t.>ri2ht$; }return t; } "oid displa5#node t$ { i%#t7=NULL$ { displa5#t.>le%t$; print%#&+d 't&,t.>data$; displa5#t.>ri2ht$; } } int del#node t,int x$ { struct tree *temp; i%#t==NULL$ print%#&'nthe element to ;e deleted is not %ound&$; else i%#x<t.>data$

t.>le%t=del#t.>le%t,x$; else i%#x>t.>data$ t.>ri2ht=del#t.>ri2ht,x$; else i%#t.>le%t -- t.>ri2ht$ { temp=%indmin#t.>ri2ht$; t.>ri2ht=del#t.>ri2ht,x$; } else { temp=t; i%#t.>le%t==NULL$ t=t.>ri2ht; else i%#t.>ri2ht==NULL$ t=t.>le%t; %ree#temp$; print%#&deleted element is +d&,x$; } return t; }

OUTPUT: enter the no o% elements in tree* @ elements are* 1B B !B >B @B 1.%ind .%indmin !.%indmax >.displa5 @.delete ?.exit enter ur choice* > elements dispal5ed in inorder %ormat *1B B !B >B @B enter ur choice* 1 enter the element search *>B search element >B is %ound enter ur choice* the minimum element in tree is1B enter ur choice* ! the max element in tree is @B enter ur choice* @ enter the element to ;e deleted >B deleted element is >B enter ur choice* > elements dispal5ed in inorder %ormat *1B B !B @B enter ur choice* ?

IMPLEMENTATION OF AVL TREE #include<stdio.h> #include<conio.h> #include<alloc.h> #include<math.h> struct node { int num,le"el,;al; struct node *le%t,*ri2ht; } *root,*cnode,*p,*V,*%p,*5a,*%5a,*s; int im;al; struct node *2etnode#$; "oid main#$ { int n,i,"al; clrscr#$; print%#&'n(nter the no. o% inte2ers in the =KL tree... &$; scan%#&+d&,-n$; print%#&'n(lements +d nos* 'n&,n$; print%#&'nGtem 1* &$; scan%#&+d&,-"al$; root=2etnode#"al$; root.>le"el=B; %or#i= ;i<=n;i99$ { print%#&'nGtem +d * &,i$; scan%#&+d&,-"al$; searchWinsert#"al$; } print%#&'n=KL tree )reated 3ith root +d 'n &,root.>num$; %ixWle"el#root$; print%#&'nGF(D L(K(L P=L=N)( &$; 2etW;alance#root$; print%#&'nHone'n&$; 2etch#$; } struct node*2etnode#int "$ { struct node *node; cnode=#struct node*$malloc#si/eo%#struct node$$; cnode.>num="; cnode.>;al=B; cnode.>le%t=NULL; cnode.>ri2ht=NULL;

return#cnode$; } searchWinsert#int "al$ { %p=NULL; p=root; %5a=NULL; 5a=p; 3hile#p7=NULL$ { V=#"al<p.>num$Mp.>le%t*p.>ri2ht; i%#V7=NULL$ i%#V.>;al7=B$ { 5a=V; %5a=p; } %p=p; p=V; } V=2etnode#"al$; i%#"al<%p.>num$ %p.>le%t=V; else %p.>ri2ht=V; p=#"al<5a.>num$M5a.>le%t*5a.>ri2ht; s=p; 3hile#p7=V$ { i%#"al<p.>num$ { p.>;al=1; p=p.>le%t; } else { p.>;al=.1; p=p.>ri2ht; } } im;al=#"al<5a.>num$M1*.1; i%#5a.>;al==B$ { 5a.>;al=im;al; return; }

else i%#5a.>;al7=im;al$ { 5a.>;al=B; return; } else ;alanceWtree#$; } ;alanceWtree#$ { i%#s.>;al==im;al$ { p=s; i%#im;al==1$ ri2htrotate#5a$; else le%trotate#5a$; 5a.>;al=B; s.>;al=B; } else { i%#im;al==1$ { p=s.>ri2ht; le%trotate#s$; 5a.>le%t=p; ri2htrotate#5a$; } else { p=s.>le%t; 5a.>ri2ht=p; ri2htrotate#s$; le%trotate#5a$; } i%#p.>;al==B$ { 5a.>;al=B; s.>;al=B; } else i%#p.>;al==im;al$ { 5a.>;al=.im;al; s.>;al=B; }

else { 5a.>;al=B; s.>;al=im;al; } p.>;al=B; } i%#%5a==NULL$ root=p; else i%#5a==%5a.>ri2ht$ %5a.>ri2ht=p; else %5a.>le%t=p; return; } le%trotate#struct node *p$ { struct node *temp; V=p.>ri2ht; temp=V.>le%t; V.>le%t=p; p.>ri2ht=temp; } ri2htrotate#struct node *p$ { struct node *temp; V=p.>le%t; temp=V.>ri2ht; V.>ri2ht=p; p.>le%t=temp; } 2etW;alance#struct node *p$ { i%#p==NULL$ return; else { print%#&'n + d 't + d 't + d&,p.>num,p.>le"el,p.>;al$; 2etW;alance#p.>le%t$; 2etW;alance#p.>ri2ht$; } } %ixWle"el#p$ struct node *p; { struct node *V;

i%#p==root$ p.>le"el=B; else i%#p==NULL$ return; V=p.>le%t; i%#V7=NULL$ V.>le"el=p.>le"el91; V=p.>ri2ht; i%#V7=NULL$ V.>le"el=p.>le"el91; %ixWle"el#p.>le%t$; %ixWle"el#p.>ri2ht$; }

OUTPUT: 1.insert .deletemin !.displa5 >.exit enter 5our choice! > ! @ Denu 1.insert .deletemin !.displa5 >.exit (nter the no. o% inte2ers in the =KL tree... L (lements L nos* Gtem 1* 1 Gtem * L Gtem ! * Gtem > * J Gtem @ * ! Gtem ? * I Gtem I * > Gtem J * ? Gtem L * @ =KL tree )reated 3ith root ! GF(D L(K(L P=L=N)( ! B .1 1 1 1 B ? 1 B > .1 @ ! B J B I ! B L ! B Hone

IMPLEMENTATION OF PRIORITY !UEUE #include<stdio.h> #include<stdli;.h> #de%ine maxsi/e 1BBB #de%ine minpVsi/e 1B #de%ine mindata .! I?I t5pede% int elementt5pe; struct heapstruct; t5pede% struct heapstruct*Nriorit5Xueue; Nriorit5Xueue initiali/e#int maxelements$; "oid destro5#Nriorit5Xueue Y$; "oid makeempt5#Nriorit5Xueue Y$; "oid insert#elementt5pe T,Nriorit5Xueue Y$; elementt5pe deletemin#Nriorit5Xueue Y$; elementt5pe %indmin#Nriorit5Xueue Y$; int isempt5#Nriorit5Xueue Y$; int is%ull#Nriorit5Xueue Y$; struct heapstruct { int capacit5; int si/e; elementt5pe *elements; }; Nriorit5Xueue initiali/e#int maxelements$ { Nriorit5Xueue Y; i%#maxelements<minpVsi/e$ print%#&'n priorit5 Vueue is too small&$; Y=malloc#si/eo%#struct heapstruct$$; i%#Y==NULL$ print%#&out o% space777&$; Y.>elements=malloc##maxelements91$*si/eo%#elementt5pe$$; i%#Y.>elements==NULL$ print%#&out o% space777&$; Y.>capacit5=maxelements; Y.>si/e=B; Y.>elementsABC=mindata; return Y; } "oid makeempt5#Nriorit5Xueue Y$ { Y.>si/e=B; } "oid insert#elementt5pe T,Nriorit5Xueue Y$ {

int i; i%#is%ull#Y$$ { print%#&'n priorit5 Vueue is %ull&$; return; } %or#i=99Y.>si/e;Y.>elementsAi1 C>T;i1= $ Y.>elementsAiC=Y.>elementsAi1 C; Y.>elementsAiC=T; } elementt5pe deletemin#Nriorit5Xueue Y$ { int i,child; elementt5pe minelement,lastelement; i%#isempt5#Y$$ { print%#&'n priorit5 Vueue is empt5&$; return Y.>elementsABC; } minelement=Y.>elementsA1C; lastelement=Y.>elementsAY.>si/e..C; %or#i=1;i* <=Y.>si/e;i=child$ { child=i* ; i%#child7=Y.>si/e -- Y.>elementsAchild91C<Y.>elementsAchildC$ child99; i%#lastelement>Y.>elementsAchildC$ Y.>elementsAiC=Y.>elementsAchildC; else ;reak; } Y.>elementsAiC=lastelement; return minelement; } elementt5pe %indmin#Nriorit5Xueue Y$ { i%#7isempt5#Y$$ return Y.>elementsA1C; print%#&priorit5 Vueue is empt5&$; return Y.>elementsABC; } int isempt5#Nriorit5Xueue Y$ { return Y.>si/e==B; } int is%ull#Nriorit5Xueue Y$

{ return Y.>si/e==Y.>capacit5; } "oid destro5#Nriorit5Xueue Y$ { %ree#Y.>elements$; %ree#Y$; } "oid displa5#Nriorit5Xueue Y$ { int i; i%#isempt5#Y$$ print%#&pV empt5&$; else { %or#i=1;i<=Y.>si/e;i99$ print%#&+d'n&,Y.>elementsAiC$; } } main#$ { Nriorit5Xueue Y; int i,Z,choice,item; Y=initiali/e#maxsi/e$; clrscr#$; do { print%#&'nDenu'n1.insert'n .deletemin'n!.displa5'n>.exit'n&$; print%#&'nenter 5our choice&$; scan%#&+d&,-choice$; s3itch#choice$ { case 1* print%#&'nenter the item to ;e inserted&$; scan%#&+d&,-item$; insert#item,Y$; ;reak; case * item=deletemin#Y$; print%#&'ndeleted element is +d&,item$; ;reak; case !* displa5#Y$; ;reak; de%ault* exit#1$; } }3hile#1$; }

OUTPUT Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice1 enter the item to ;e inserted1 Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice1 enter the item to ;e inserted Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice1 enter the item to ;e inserted! Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice1 enter the item to ;e inserted> Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice1 enter the item to ;e inserted@ Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice! 1 ! >

@ Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice deleted element is 1 Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice! > ! @ Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice! > ! @ Denu 1.insert .deletemin !.displa5 >.exit enter 5our choice>

IMPLEMENTATION OF "AS"ING #IT" OPEN ADDRESSING #include<stdio.h> #include<conio.h> #include<malloc.h> int arA1BC,i,2=B,ke5; "oid insert#$; "oid delete#$; "oid displa5#$; main#$ { int ch; clrscr#$; %or#i=B;i<1B;i99$ arAiC=.1; do { print%#&'n't'tD(NU 'n1.insert 'n .displa5 'n!.(xit'n&$; scan%#&+d&,-ch$; s3itch#ch$ { case 1*insert#$; ;reak; case *displa5#$; ;reak; case !*;reak; de%ault* print%#&'nGn"alid choice entr5777'n&$; ;reak; } }3hile#ch<!$; } "oid insert#$ { int item,%=B; print%#&'nenter the elements to ;e inserted* &$; scan%#&+d&,-item$; ke5=#item+1B$.1; i%#arAke5C==.1$ { arAke5C=item; %=1; } else { i%#ke5<L$ {

%or#i=ke591;i<1B;i99$ { i%#arAiC==.1$ { %=1; arAiC=item; ;reak; } } } i%#%==B$ { %or#i=B;i<ke5;i99$ { i%#arAiC==.1$ { %=1; arAiC=item; ;reak; }}}} i%#%==B$ print%#&'nhashta;le is %ull'n&$; } "oid displa5#$ { %or#i=B;i<1B;i99$ i%#arAiC7=.1$ { 2=1; ;reak; } i%#2==1$ { %or#i=B;i<1B;i99$ { i%#arAiC==.1$ print%#&'n...&$; else print%#&'n+d&,arAiC$; } } else print%#&'nthe hashta;le is empt5777&$; print%#&'n&$; }

OUTPUT D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* 1 D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* ! D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* > D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* @ D(NU 1.insert .displa5 !.(xit

1 ! > @ ... ... ... ... ... D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* ? D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* I D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* J D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* L

D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* 1B D(NU 1.insert .displa5 !.(xit 1 enter the elements to ;e inserted* 11 Yashta;le is %ull D(NU 1.insert .displa5 !.(xit

1 ! > @ ? I J L 1B D(NU 1.insert .displa5 !.(xit !

IMPLEMENTATION OF PRIM$S ALGORIT"M #include<stdio.h> #include<conio.h> #de%ine D=T 1B #de%ine F(DN B #de%ine N(ED 1 #de%ine :=L<( B #de%ine FEU( 1 #de%ine in%init5 LLLL struct node { int predecessor; int dist; int status; }; struct ed2e { int u; int "; }; int adZAD=TCAD=TC; int n; "oid main#$ { int i,Z; int pathAD=TC; int 3tWtree,count; struct ed2e treeAD=TC; clrscr#$; createW2raph#$; print%#&adZacenc5 matrix is *'n&$; displa5#$; count=maketree#tree,-3tWtree$; print%#&[ei2ht o% spannin2 tree is +d'n&,3tWtree$; print%#&(d2es to ;e included in spannin2 tree are*'n&$; %or#i=1;i<=count;i99$ { print%#&+d'n&,treeAiC.u$; print%#&+d'n&,treeAiC."$; } 2etch#$; } createW2raph#$ { int i,maxWed2es,ori2in,destin,3t;

print%#&(nter num;er o% "ertices*&$; scan%#&+d&,-n$; maxWed2es=n*#n.1$1 ; %or#i=1;i<=maxWed2es;i99$ { print%#&enter ed2e +d#B B to Vuit$*&,i$; scan%#&+d +d&,-ori2in,-destin$; i%##ori2in==B$ -- #destin==B$$ ;reak; print%#&(nter 3ei2ht %or this ed2e*&$; scan%#&+d&,-3t$; i%#ori2in>n 66 destin>n 66 ori2in<=B 66 destin<=B$ { print%#&Gn"alid ed2e7'n&$; i..; } else { adZAori2inCAdestinC=3t; adZAdestinCAori2inC=3t; } } } displa5#$ { int i,Z; %or#i=1;i<=n;i99$ { %or#Z=1;Z<=n;Z99$ print%#&+!d&,adZAiCAZC$; print%#&'n&$; } } int maketree#struct ed2e treeAD=TC,int *3ei2ht$ { struct node stateAD=TC; int i,k,min,count,current,ne3dist; int m; int u1,"1; *3ei2ht=B; %or#i=1;i<=n;i99$ { stateAiC.predecessor=B; stateAiC.dist=in%init5; stateAiC.status=F(DN; }

stateA1C.predecessor=B; stateA1C.dist=B; stateA1C.status=N(ED; current=1; count=B; 3hile#allWperm#state$7=FEU($ { %or#i=1;i<=n;i99$ { i%#adZAcurrentCAiC>B -- stateAiC.status==F(DN$ { i%#adZAcurrentCAiC<stateAiC.dist$ { stateAiC.predecessor=current; stateAiC.dist=adZAcurrentCAiC; } } } min=in%init5; %or#i=1;i<=n;i99$ { i%#stateAiC.status==F(DN -- stateAiC.dist<min$ { min=stateAiC.dist; current=i; } } stateAcurrentC.status=N(ED; u1=stateAcurrentC.predecessor; "1=current; count99; treeAcountC.u=u1; treeAcountC."="1; *3ei2ht=*3ei2ht9adZAu1CA"1C; } return#count$; } int allWperm#struct node stateAD=TC$ { int i; %or#i=1;i<=n;i99$ i%#stateAiC.status==F(DN$ return :=L<(; return FEU(; }

Vous aimerez peut-être aussi