dats_structurelab manual r 2004
TRANSCRIPT
-
8/13/2019 Dats_structurelab Manual r 2004
1/60
Array Implementation of Linked List
Exp No:1
Aim:
To write a program to implement the linked list using array.
Algorithm:
Step 1:Start.
Step 2:Read the size and elements o the array.
Step !:Read the re"uired #hoi#e.
Step $:Read the elements and position or insertion.
Step %:&nsert and display the array elements.
Step ':(or deletion read the position o the element.
Step ):*isplay the deleted element.
Step +:(or rea#hing read the num,er to ,e sear#hed.
Step -:*isplay the element position.
Step 1:Stop.
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h
0deine size 1
stru#t array
3
int 4alue5
int #hain5
6
a7size85
4oid main9
1
-
8/13/2019 Dats_structurelab Manual r 2004
2/60
3
int n;i;position;#hoi#e;start5
#har ans5
int #reate9stru#t array a78;int5
4oid display9stru#t array a78;int5int sear#h9stru#t array a78;int;int5
#lrs#r95
print9ist
-
8/13/2019 Dats_structurelab Manual r 2004
3/60
while9ansDDHyH5
get#h95
6
int #reate9stru#t array a7size8;int n
3
int i;lagD;index;startIindex;pre4Iindex5i9nsize
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
4/60
6
int sear#h9stru#t array a7size8;int startIindex;int position
3
int i;#ountD5
or9iDstartIindex5a7i8.#hainGDF--5iDa7i8.#hain
3#ount5
i9#ountDDposition
return i5
6
print9
*o you want to #ontinue.......
4
-
8/13/2019 Dats_structurelab Manual r 2004
5/60
Enter your #hoi#e:
!
Enter the position or sear#hing:2
The 2 position indi#ates as a 4alue 21
*o you want to #ontinuePP.
Result:
Thus the program or array implementation using linked list has
,een exe#uted su##essully and output is 4eriied.
5
-
8/13/2019 Dats_structurelab Manual r 2004
6/60
Implementation of Linked List Using Pointer
Exp No:2
Aim:
To write a program to implement the linked list using pointer.
Algorithm:
Step 1:start.
Step 2:#all un#tion #reate9nodeQpStep !:#all #ount9nodeQp
Step $:headD9nodeQmallo#9sizeo9node
Step %:#reate9head
Step ':print head.
Step ):stop.
?reation o list:
Step 1:read listFnum,er
Step 2:i9listFnum,erDDF--;then
Step !:listFnext the NJ>>;else
Step $:listFnextD9nodeQmallo#9sizeo9node
Step %:#reate9list1;next
Step ':return
Step ):stop
Sear#h:
6
-
8/13/2019 Dats_structurelab Manual r 2004
7/60
Step1:et the element whi#h to ,e sear#hed.
Step 2:i9tempFdataGDkey
Step !:tempDtempFnext; Else
Step $:oundDTRJE5Step%:The element is present is the list
Step':else Element is not present in the list
*elete:
Step1:et the Element whi#h is to ,e *eleted.
Step2: tempDsear#h9Qhead;key5
Step!: i9tempGDNJ>>
Step$:pre4DgetIpre49Qhead;key5
Step%:i9pre4GDNJ>>
Step':pre4FnextDtempFnext5
Step):ree9temp5else
Step+:QheadDtempFnext5
Step-:ree9temp5
Step1:The element is deleted
*isplay:
Step 1:i9listFnextGDNJ>>then print listFnum,er
Step 2:return
Step !:int #ount9nodeQlist
Step $:i9listnextDDNJ>>;return;else
Step %:return91#ount9listFnext
Step ':return
Step ):stop
7
-
8/13/2019 Dats_structurelab Manual r 2004
8/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h
0deine TRJE 10deine (A>SE
typede stru#t S>>
3
int data5
stru#t S>> Qnext5
6node5
node Q#reate95
4oid main9
3
int #hoi#e;4al5#har ans5
node Qhead5
4oid display9nodeQ5
node Qsear#h9nodeQ;int5
4oid insert9nodeQ5
4oid dele9nodeQQ5
headDNJ>>5
do
3
#lrs#r95print9inked >ist
-
8/13/2019 Dats_structurelab Manual r 2004
9/60
print9
-
8/13/2019 Dats_structurelab Manual r 2004
10/60
3
tempFnextDNew5
tempDNew5
6
print9
3print9
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
11/60
int ound5
tempDhead5
i9tempDDNJ>>
3
print95
6
oundD(A>SE5
while9tempGDNJ>>Gound
3
i9tempFdataGDkey
tempDtempFnext5
else
oundDTRJE56
i9ound
3
print9
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
12/60
s#an9
s#an9print95
NewFnextDtempFnext5
tempFnextDNew5
print9
return NJ>>5
lagD(A>SE5
pre4DNJ>>5
while9tempGDNJ>>Glag
3i9tempFdataGD4al
3
pre4Dtemp5
tempDtempFnext5
6
else
lagDTRJE5
6
i9lag
return pre45
else
return NJ>>5
6
4oid dele9node QQhead
3
node Qtemp;Qpre45
int key5
12
-
8/13/2019 Dats_structurelab Manual r 2004
13/60
tempDQhead5
i9tempDDNJ>>
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
14/60
Enter the element:
11
*o u want to enter more elementsC9yKnC
Enter the element:
1$*o u want to enter more elementsC9yKnC
Enter the element:
1%
*o u want to enter more elementsC9yKnC
The singly list is #reated:
Enter your #hoi#e:
2
11F1$F1%FNJ>>
Enter your #hoi#e:
!
Enter the element u want to sear#h:
11
The element is present is the list.
Enter the element ater whi#h is want to insertC
11
The element is present is the list.--
The element is inserted.
Enter the element u want to delete:
--
The element is present is the list.
Result:
Thus the program or implementation o linked list using pointerhas ,een exe#uted su##essully and output is 4eriied.
14
-
8/13/2019 Dats_structurelab Manual r 2004
15/60
Cursor Implementation of List
Exp No:!
Aim:
To write a program or #ursor implementation o linked list.
Algorithm:
Step 1:Start.
Step 2:Read the size and elements o the array.
Step !:Read the re"uired #hoi#e.
Step $:Read the elements and position or insertion.
Step %:&nsert and display the array elements.
Step ':(or deletion read the position o the element.
Step ):*isplay the deleted element.
Step +:(or rea#hing read the num,er to ,e sear#hed.
Step -:*isplay the element position.
Step 1:Stop.
15
-
8/13/2019 Dats_structurelab Manual r 2004
16/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h
0deine MAU 2int list7MAU85
4oid main9
3
int #hoi#e;len;pos5
int #reate95
#har ans5
4oid display9int5
int sear#h9int5
4oid delet9int5
do3
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
17/60
i9ansDDHyH
exit95
else
,reak5
deault:
#lrs#r95print9
-
8/13/2019 Dats_structurelab Manual r 2004
18/60
int sear#h9int n
3
int i;key5
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
19/60
Sample &nputKLutput:
Main menu
1.?reate
2.*isplay!.Sear#h
Enter your #hoi#e:
1
Bow many elements do you want to listC
!
Enter the lo#ation and 4alue at that lo#ation:
$ 2
% 21
' 22*o you want to #ontinue.......
Enter your #hoi#e:
2
ou ha4e entered the list 2 O 21O 22ONJ>>
*o you want to #ontinue.......
Enter your #hoi#e:
!
Enter the position or sear#hing:2
The 2 position indi#ates as a 4alue 21
*o you want to #ontinuePP.
Result:
Thus the program or #ursor implementation o linked list has
,een exe#uted su##essully and output is 4eriied.
19
-
8/13/2019 Dats_structurelab Manual r 2004
20/60
Implementation of Stack Using Array
Exp No:$
Aim:
To write a program to implement a sta#k using array.
Algorithm:
Step 1:start.
Step 2:read the re"uired #hoi#e using swit#h #ase.Step !:#all the re"uired un#tions.
Step $:stop.
/ush:
Step 1:#he#k i sta#k is ull; then
Step 2:display sta#k o4erlows; else
Step !:#he#k i sta#k is empty; then
Step $:read the 4alue ,y in#rementing top 4alue
Step %:stop.
/op:
Step 1:#he#k i the sta#k is empty; then
Step 2:display sta#k underlows; else
Step !:#he#k i top is not e"ual to ; then
Step $:display the top 4alue and delete the element
Step %:stop.
20
-
8/13/2019 Dats_structurelab Manual r 2004
21/60
*isplay:
Step 1:#he#k whether the sta#k is empty.
Step 2:display the sta#k.Step !:stop.
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h
0deine size %
stru#t sta#k
3
int s7size85
int top5
6
st5
int stull9
3
i9st.topDsizeF1
return 15
else
return 5
64oid push9int item
3
st.top5
st.s7st.top8Ditem5
6
int stempty9
3
i9st.topDDF1
return 15
elsereturn 5
6
int pop9
3
int item5
itemDst.s7st.top85
21
-
8/13/2019 Dats_structurelab Manual r 2004
22/60
st.topFF5
return9item5
6
4oid display9
3
int i5i9stempty9
print9
-
8/13/2019 Dats_structurelab Manual r 2004
23/60
#ase !:
display95
,reak5
#ase $:exit95
6
print9
-
8/13/2019 Dats_structurelab Manual r 2004
24/60
Enter your #hoi#e:
2
Enter The &tem to ,e poped: %'
*o you want to #ontinueC
Enter your #hoi#e:
!
!!
11
*o you want to #ontinueC
Enter your #hoi#e:$
Result:
Thus the program or implement a sta#k using array has ,een
exe#uted su##essully and output is 4eriied.
24
-
8/13/2019 Dats_structurelab Manual r 2004
25/60
Implementation of Stack Using Linked List
Exp No:%
Aim:
To write a program to implement a sta#k using linked list.
Algorithm:
Step 1:Start.
Step 2:Read the #hoi#e.
Step !:?all the re"uired un#tions.
Step $:Stop.
/ush:
Step 1:?he#k i sta#k is ull.then
Step 2:Read the 4alue to ,e pushed.
Step !:Stop.
/op:
Step 1:?he#k i sta#k is empty;then
Step 2:*eleted the top 4alue.
Step !:*isplay the popped element.
Step $:Stop.
25
-
8/13/2019 Dats_structurelab Manual r 2004
26/60
*isplay:
Step 1:?he#k i sta#k is empty.
Step 2:*isplay the sta#k.
Step !:Stop.
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludepro#ess.h
0in#ludestdli,.h
0in#ludeallo#.h
typede stru#t sta#k
3
int data5
stru#t sta#k Qnext5
6
node5
4oid main9
3
node Qtop5
int data;item;#hoi#e5
#har ans;#h5
4oid push9int;node QQ54oid display9node QQ5
int pop9node QQ5
int sempty9node Q5
#lrs#r95
topDNJ>>5
print9inked list
-
8/13/2019 Dats_structurelab Manual r 2004
27/60
push9data;top5
,reak5
#ase 2:
i9sempty9top
print9
-
8/13/2019 Dats_structurelab Manual r 2004
28/60
print95
return9temp5
6
int sempty9nodeQtemp3
i9tempDDNJ>>
return 15
else
return 5
6
int pop9node QQtop
3
int item5
node Qtemp5itemD9QtopFdata5
tempDQtop5
QtopD9QtopFnext5
ree9temp5
return9item5
6
4oid display9node QQhead
3
node Qtemp5
tempDQhead5i9sempty9temp
print9
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
29/60
Sample &nputKLutput:
Main menu
1./ush
2.pop!.*isplay
$.Exit
Enter your #hoi#e:1
Enter The *ata:11
Enter your #hoi#e:1
Enter The *ata:!$
*o you Want To ?ontinueC
Enter your #hoi#e:!
!$11
*o you Want To ?ontinueC
Enter your #hoi#e:2
The /oped Node &s:!$
*o you Want To ?ontinueC
Enter your #hoi#e:$
Result:
Thus the program to implement a sta#k using array has ,een exe#utedsu##essully and output is 4eriied.
29
-
8/13/2019 Dats_structurelab Manual r 2004
30/60
Implementation of Queue Using Array
Exp No:'
Aim:
To write a program to implement a ueue using array.
Algorithm:
Step 1:Start.
Step 2:Read the re"uired #hoi#e using swit#h #ase.
Step !:?all the re"uired un#tions.
Step $:Stop.
En"ueue:
Step 1:?he#k i "ueue is ull;then
Step 2:*isplay "ueue o4erlows.else;
Step !:?he#k i "ueue is empty;then
Step $:Read the 4alue ,y in#rementing rear 4alue.
*e"ueue:
Step 1:?he#k i "ueue is empty;then
Step 2:*isplay "ueue underlows.else
Step !:?he#k i ront e"uals rear.
Step $:*isplay the deleted element.
*isplay:
Step 1:?he#k whether "ueue is empty.
Step 2:*isplay the "ueue.Step !:Stop.
30
-
8/13/2019 Dats_structurelab Manual r 2004
31/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h0deine size %
stru#t "ueue
3
int "ue7size85
int ront;rear5
6
"5
"ull9
3
i9".rearDsizeF1return 15
else
return 5
6
int insert9int item
3
i9".rontDDF1
".ront5
"."ue7".rear8Ditem5
return ".rear56
int "empty9
3
i99".rontDDF1VV9".ront".rear
return 15
else
return 5
6
int dele9
3int item5
itemD"."ue7".ront85
".ront5
print9
-
8/13/2019 Dats_structurelab Manual r 2004
32/60
3
int i5
or9iD".ront5iD".rear5i
print9
-
8/13/2019 Dats_structurelab Manual r 2004
33/60
deault:print9
-
8/13/2019 Dats_structurelab Manual r 2004
34/60
Implementation of Queue Using Pointer
Exp No:)
Aim:
To write a program or implement a ueue using pointer.
Algorithm:
Step 1:Start.
Step 2:Read the re"uired #hoi#e.
Step !:Stop
En"ueue:
Step 1:?he#k i "ueue is ull;then
Step 2:*isplay "ueue o4erlow.else;
Step !:Read the 4alue ,y in#rementing the rear 4alue.
*e"ueue:
Step 1:?he#k i "ueue is empty;then
Step 2:*isplay "ueue underlows;else
Step !:*isplay the deleted element in the ront position.
*isplay:
Step 1:?he#k i "ueue is empty;then
Step 2:*isplay "ueue underlows;else
Step !:*isplay the "ueue.
Step $:Stop.
34
-
8/13/2019 Dats_structurelab Manual r 2004
35/60
/rogram:
0in#ludestdio.h
0in#ludestdli,.h
0in#lude#onio.h
typede stru#t node3
int data5
stru#t node Qnext5
65
Qront;Qrear5
4oid main94oid
3
#har ans5
int #hoi#e5
4oid En"ueue95 Q*e"ueue95
4oid display9 Q5
rontDNJ>>5
rearDNJ>>5
do
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
36/60
ansDget#h95
6
while9ansDDHyHVVansDDHH5
get#h95
#lrs#r95
6 QgetInode9 Qtemp
3
tempD9Qmallo#9sizeo95
tempFnextDNJ>>5
return temp5
6
4oid insert9
3
#har #h5
Qtemp5#lrs#r95
tempDgetInode9temp5
print9
return 15
else
return 5
6
Qdelet9
3
Qtemp5
tempDront5
i9empty9ront
36
-
8/13/2019 Dats_structurelab Manual r 2004
37/60
3
print9
-
8/13/2019 Dats_structurelab Manual r 2004
38/60
Sample &nputKLutput:
Main Menu
1.En"ueue2.*e"ueue
!.*isplay
Enter Jr ?hoi#e: 1
Enter The Num,er To Xe En"ueue: 11
*o J want To ?ontinue9KNC
Enter Jr ?hoi#e:1
Enter The Num,er To Xe En"ueue:!$
Enter Jr ?hoi#e:2
Enter The Num,er To Xe *e"ueue:11
Enter Jr ?hoi#e:!
!$
Result:
Thus the program or implement a ueue using pointer has ,een
exe#uted su##essully and output is 4eriied.
38
-
8/13/2019 Dats_structurelab Manual r 2004
39/60
Welformed Balanced Paranthesis Using Array
Exp No:+
Aim:
To write a program or welormed ,alan#ed paranthesis using
array.
Algorithm:
Step1:?reate an Empty Sta#k.
Step2:Read the ?har#ter until the ile.
Step!:& the ?hara#ter is opening sym,olthen push it into the sta#k.
Step$:& the #hara#ter is an opening sym,ol and & the sta#k is empty
report an error else pop it rom the sta#k.
Step%:& the sym,ol is not the #orresponding opening Sym,ol then report
an error.
Step':At the end o ile; i the sta#k is not empty;report an error.
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h
0deine size %
stru#t sta#k
3#har s7size85
int top5
6st5
4oid push9#har item
3
st.top5
39
-
8/13/2019 Dats_structurelab Manual r 2004
40/60
st.s7st.top8Ditem5
6
int stempty9
3
i9st.topDDF1
return 15else
return 5
6
#har pop9
3
#har item5
itemDst.s7st.top85
st.topFF5
return9item5
64oid main94oid
3
#har item5
#har ans;,ra#ket7185
int i5
st.topDF15
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
41/60
-
8/13/2019 Dats_structurelab Manual r 2004
42/60
Welformed Balanced Paranthesis Using pointer
Exp No:-
Aim:
To write a program or welormed ,alan#ed paranthesis using
pointer.
Algorithm:
Step1:?reate an Empty Sta#k.
Step2:Read the ?har#ter until the ile.
Step!:& the ?hara#ter is opening sym,olthen push it into the sta#k.
Step$:& the #hara#ter is an opening sym,ol and & the sta#k is empty
report an error else pop it rom the sta#k.
Step%:& the sym,ol is not the #orresponding opening Sym,ol then report
an error.
Step':At the end o ile; i the sta#k is not empty;report an error.
42
-
8/13/2019 Dats_structurelab Manual r 2004
43/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludepro#ess.h
0in#ludestdli,.h0in#ludeallo#.h
0in#ludesta#ks.h
4oid main94oid
3
#har ans;,ra#ket7185
#har item5
node Qtop5
int #hoi#e5
int i5
4oid push9#har;nodeQQ54oid *isplay9node QQ5
#har pop9nodeQQ5
int Sempty9node Q5
topDNJ>>5
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
44/60
6
i5
6
while9,ra#ket7i8GDHYH5
i9GSempty9top
print9
-
8/13/2019 Dats_structurelab Manual r 2004
45/60
NewFnextDQtop5
QtopDNew5
6
node QgetInode9#har item
3
node Qtemp5tempD9node Qmallo#9sizeo9node5
i9tempDDNJ>>
print95
return9temp5
6
int Sempty9node Qtemp
3
i9tempDDNJ>>return 15
else
return 5
6
#har pop9node QQtop
3
#har item5
node Qtemp5
itemD9QtopFdata5
tempDQtop5QtopD9QtopFnext5
ree9temp5
return9item5
6
Sample &nputKLutput:
Enter the Expression and put Yat the end
99Y
The exp has well (ormed parenthesis
Enter the Expression and put Yat the end99Y
The expression is in4alid
Result:
Thus the program or welormed ,alan#ed parenthesis using
pointer has ,een exe#uted su##essully and output is 4eriied.
45
-
8/13/2019 Dats_structurelab Manual r 2004
46/60
Ealuating Postfi! E!pression Using Array
Exp No:1
Aim:
To write a program or e4aluating postix using array.
Algorithm:
Step 1:Start.Step 2:Read the postix expression rom let to right.
Step !:& the input sym,ol is an operand then;
Step $:/ush it on to the sta#k.
Step %:& the operator is read /L/ two operands and
perorm arithmeti# operations
Step ':& operator is
then resultDoperand1operand2
F then resultDoperand1Foperand2
Q then resultDoperand1Qoperand2
K then resultDoperand1Koperand2
Step ):/ush the result on to the sta#k.
Step +:Repeat steps 1F$ till the postix expression is not
o4er.
Step -:Stop.
46
-
8/13/2019 Dats_structurelab Manual r 2004
47/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h0in#ludestring.h
0in#ludemath.h
0in#lude
-
8/13/2019 Dats_structurelab Manual r 2004
48/60
3
4alD #h F $+5
push94al5
6
else
i9str#mp9type;
-
8/13/2019 Dats_structurelab Manual r 2004
49/60
KKArrayIst.h Beader (ile
0in#ludestdio.h
0in#lude#onio.h
0deine MAU 1
stru#t sta#k3
dou,le s7MAU85
int top5
6
st5
4oid push9dou,le 4al
3
i9st.top1DMAU
print9
-
8/13/2019 Dats_structurelab Manual r 2004
50/60
Ealuating Postfi! E!pression Using Linked List
Exp No:11
Aim:
To write a program or e4aluating postix using >inked list.
Algorithm:
Step 1:Start.
Step 2:Read the postix expression rom let to right.
Step !:& the input sym,ol is an operand then;
Step $:/ush it on to the sta#k.
Step %:& the operator is read /L/ two operands and
perorm arithmeti# operations
Step ':& operator is
then resultDoperand1operand2
F then resultDoperand1Foperand2
Q then resultDoperand1Qoperand2
K then resultDoperand1Koperand2
Step ):/ush the result on to the sta#k.
Step +:Repeat steps 1F$ till the postix expression is noto4er.
Step -:Stop.
50
-
8/13/2019 Dats_structurelab Manual r 2004
51/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
0in#ludestdli,.h0in#ludestring.h
0in#ludemath.h
0in#lude
-
8/13/2019 Dats_structurelab Manual r 2004
52/60
i9str#mp9type;
-
8/13/2019 Dats_structurelab Manual r 2004
53/60
Sample &nputKLutput
Enter the postix Expression
12!$Q
The 4alue o the exp is1%.
Result:
Thus the program or e4aluating postix using >inked listhas ,een exe#uted su##essully and output is 4eriied.
53
-
8/13/2019 Dats_structurelab Manual r 2004
54/60
"EAP S#$%
Exp No:12
Aim:
To write a program to sort the elements using Beap sort.
Algorithm:
Step 1:start
Step 2:read the elements to ,e sorted.
Step !:i the elements are to sorted in an as#ending order;
do the ollowing to sort;until there is no other
element.
Step !.1:apply deletemin9 routine to get the smallest
element rom the array.
Step !.2:store the elements returned ,y deletemin in
the last position in the array.
Step !.!:de#rement the num,er o elements ,y one.
Step $:stop the pro#ess.
54
-
8/13/2019 Dats_structurelab Manual r 2004
55/60
/rogram:
0in#ludestdio.h
0in#lude#onio.h
4oid heap9int a78;int n5
4oid #reateIheap9int a78;int n54oid main9
3
int a7%8;i;n5
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
56/60
3
int i;\;";key;temp5
#reateIheap9a;n5
or9"DnF15"D15"FF
3
tempDa785a78Da7"85
a7"8Dtemp5
iD5
keyDa785
\D15
i99\1"
i9a7\18a7\8
\D\15
while99\D9"F19a7\8key
3a7i8Da7\85
iD\5
\D2Qi5
i99\1"
i9a7\18"
\D\15
else i9\nF1
\DnF15
a7i8Dkey5
66
6
56
-
8/13/2019 Dats_structurelab Manual r 2004
57/60
Sample &nputKLutput
Enter the limit:%
Enter the elements11
!$
--$%
22
The sorted list is:
22
!$
$%
--
11
Result:
Thus the i4en Elements is sorted using Beap sort and output is
]eriied.
57
-
8/13/2019 Dats_structurelab Manual r 2004
58/60
QUIC& S#$%
Exp No:1!
Aim:
To write a program to sort the elements using ui#k sort.
Algorithm:
Step 1:start.Step 2:read the limit and elements.
Step !:#all the un#tion.
Step $:display the sorted list.
Step %:stop.
ui#k sort:
Step 1:#ompute the pi4ot element.
Step 2:sort the list.
Step !:swap i ne#essary.
Step $:stop.
58
-
8/13/2019 Dats_structurelab Manual r 2004
59/60
/rogram:
0in#ludestdio.h
0in#ludestdli,.h
0in#lude#onio.h
0deine MAU 14oid main9
3
int n;i;x7MAU85
4oid "ui#k9int x78;int;int5
#lrs#r95
print9
-
8/13/2019 Dats_structurelab Manual r 2004
60/60
3
i9x7i8pi4ot
3
lowerDlower15
inter#hange9x;lower;i5
66
inter#hange9x;l,;lower5
"Dlower5
return9"5
6
4oid inter#hange9int x7MAU8;int a;int ,
3
int temp5
tempDx7a85
x7a8Dx7,85x7,8Dtemp5
6
Sample &nputKLutput
Enter how many elements do u want sort %
Enter the Elements:12
Enter the Elements:))
Enter the Elements:+
Enter the Elements:1
Enter the Elements:
The sorted Elements are 1 12 )) +
Result:
Thus the i4en elements are sorted using ui#k sort and
output is 4eriied.
60