Sem 2: Data Structures Practical
-
Upload
metalwihen -
Category
Documents
-
view
228 -
download
0
Transcript of Sem 2: Data Structures Practical
-
8/2/2019 Sem 2: Data Structures Practical
1/44
-
8/2/2019 Sem 2: Data Structures Practical
2/44
1
2
3
5
7
1
1
1
1
1
ONT
. WritDele
. WA
. WA
. WA
. WA
. WA
. WA
. WA
. WA0. WA1. WA
2. WAon2
3. WA4. WA
NTS
eaProg
tion,Sea
toperf
toperf
toperf
to
perf
toperf
toperf
toimpl
toimpl
toimpl
toimpl
toperf
TwoDi
toimpl
toimpl
amusin
rching,S
rmBubb
rmSelec
rmInser
rmMer
rmLinea
rmBina
mentSt
mentQ
mentSi
mentD
rmAddi
ensiona
mentSt
mentQ
Arrays
rtingan
leSort.
tionSort
tionSort
eSort.
rSearch.
ySearch
cksusin
euesusi
glyLink
ublyLin
ion,Sub
lArray.
cksusin
euesusi
erformi
dTraver
.
.
.
.
gArrays.
ngArray
dLists.
edLists.
raction
gLinked
ngLinke
gInserti
ingOpe
.
ndMulti
Lists.
Lists.
on,
ations.
plication
-
8/2/2019 Sem 2: Data Structures Practical
3/44
#
i
i
{
}
v
{
}
v
{
/ Writ
nserti
ravers
include
ze of arr
(int *a,i
=0,end=n-
;
beg
-
8/2/2019 Sem 2: Data Structures Practical
4/44
}
v
{
}
v
{
}
i
{
{
for(i
a[i]=
n--;
print
}
else
print
oid INS(i
int p
//Fin
if(IT
pos=n;
else
pos=0;
else
{f
i
{
}
}
//Shi
for(i
a[i]=
a[pos]
n++;
print
oid Displ
int
for(
prin
nt main()
int a[
printf(
scanf("
printf(
for(i=
scanf("
do
pos; ia[n-1])
f(ITEM
-
8/2/2019 Sem 2: Data Structures Practical
5/44
{
print
print
print
print
print
print
print
print
scanf(
switc
{
case
prin
scan
SSor
INS(
Disp
brea
case
prin
scan
SSor
DEL(
Disp
brea
case
prin
scan
SSor
pos=
if(p
prin
else
prin
brea
case
prin
SSor
Disp
brea
case
("\n ____("\n MENU("\n 1. I("\n 2. D("\n 3. S("\n 4. D("\n 0. E("\n Your
"%d",&ch)
(ch)
1: //INSE
f("\n Ent
("%d",&IT
(a);
,ITEM);
ay(a);
;
2: //DELE
f("\n Ent
("%d",&IT
(a);
,ITEM);
ay(a);
;
3: //SEAR
f("\n Ent
("%d",&IT
(a);
Search(a,
s==-1)
f("\n Ite
f("\n Ite
;
4: //DISP
f("\n The
(a);
ay(a);
;
0:
________
:\n");sert an e
lete an e
arch for
isplay ele
it. ");
Choice: "
;
T
r the Ite
M);
TE
r the Ite
M);
H
r the Ite
M);
ITEM);
not Fou
found at
AY
Elements
_________
lement. "
lement. "
an elemen
ments. ")
);
m to Inse
m to Dele
m to Sear
d. ");
%d posit
are: ");
________
);
);
t. ");
;
rt: ");
te: ");
ch: ");
ion. ",pos
_____ ");
+1);
-
8/2/2019 Sem 2: Data Structures Practical
6/44
}
O
prin
brea
}
}whi
UTPUT:
Enter the
Enter the
_________
MENU:
1. Insert
2. Delete
3. Search
4. Displa
0. Exit.
Your Choi
The Eleme
_________
MENU:
1. Insert
2. Delete
3. Search
4. Displa
0. Exit.Your Choi
Enter the
Item Inse
_________
MENU:
1. Insert
2. Delete
3. Search
4. Displa
0. Exit.
Your Choi
Enter the
Item foun
f("\n Exi;
e(ch!=0);
number of
Elements:
_________
an elemen
an elemen
for an el
elements
e: 4
ts are:
_________
an elemen
an elemen
for an el
elements
e: 1
Item to I
ted. 2 4
_________
an elemen
an elemen
for an el
elements
e: 3
Item to S
at 5 pos
ing... ")
Elements:
10 2 8 4
________
.
.
ment.
.
4 6 8 10
________
.
.
ment.
.
sert: 7
6 7 8 10
________
.
.
ment.
.
arch: 8
ition.
;
5
6
_________
_________
_________
-
8/2/2019 Sem 2: Data Structures Practical
7/44
_________
MENU:
1. Insert
2. Delete
3. Search4. Displa
0. Exit.
Your Choi
Enter the
Item Dele
_________
MENU:
1. Insert
2. Delete
3. Search
4. Displa
0. Exit.
Your Choi
Exiting...
_________
an elemen
an elemen
for an elelements
e: 2
Item to D
ed. 2 6
_________
an elemen
an elemen
for an el
elements
e: 0
________
.
.
ment..
lete: 4
8 10
________
.
.
ment.
.
_________
_________
-
8/2/2019 Sem 2: Data Structures Practical
8/44
#
v
{i
f
f
i
{
t
a
a
}
}
m
{
i
p
s
p
f
s
B
pf
p
}O
E
E
E
2
/ Writ
includea[
emp=a[j+1]
[j+1]=a[j]
[j]=temp;
ain()
nt a[50],
rintf("En
canf("%d",
rintf("En
or(i=0; i
canf("%d",
sort(a,n);
rintf("\nor(i=0; i
rintf("%d
UTPUT:
nter size
nter elem
lements:
4 5 6 8
A Pro
dio.h>
int *a,in
p;
i>=0; i--
i; j++)
+1])
;
;
,i;
er size o
&n);
er elemen
n; i++)
&a[i]);
lements:n; i++)
",a[i]);
of your a
nts of yo
ram to
n)
)
your ar
s of you
n");
ray: 5
r array:
perfor
ay: ");
array: "
2 8 4 6 5
m a bu
);
ble so t.
-
8/2/2019 Sem 2: Data Structures Practical
9/44
#
v
{i
f
f
i
{
t
a
a
}
}
m
{
i
p
s
p
f
s
S
pf
p
}
O
E
E
E
1
/Write
includea[
emp=a[i];;
[i]=a[j];
[j]=temp;
ain()
nt a[50],
rintf("En
canf("%d",
rintf("En
or(i=0; i
canf("%d",
sort(a,n);
rintf("\nor(i=0; i
rintf("%d
UTPUT:
nter size
nter elem
lements:
3 6 7 9
A Prog
dio.h
int *a,in
p;
n-1; i++)
j
-
8/2/2019 Sem 2: Data Structures Practical
10/44
#
v
{i
a
f
{
t
f
{
a
}
a
}
}
m
{
i
p
s
pf
s
I
p
f
p
}
O
E
E
E
2
/Write
include
int *a,in
p;
n+1; i++)
temp < a[
;
;
,i;
er size o
&n);
er elemenn+1; i++)
&a[i]);
lements:
n+1; i++)
",a[i]);
of your a
nts of yo
am to
n)
]; j--)
your ar
s of you
n");
ray: 5
r array:
erform
ay: ");
array: "
2 8 4 6 5
an In
);
ert so t.
-
8/2/2019 Sem 2: Data Structures Practical
11/44
#
v
{
}
i
{
/ Writ
include
ort(int *
0,j=0,k=0
i
-
8/2/2019 Sem 2: Data Structures Practical
12/44
}
O
printf(
for(i=
printf(
UTPUT:
Enter the
Enter the
Enter the
Enter the
The Merge
"\n The M
; i
-
8/2/2019 Sem 2: Data Structures Practical
13/44
#
i
{
if
{
i
r
}
r
}
m
{
i
i
ps
p
f
s
p
s
p
i
pe
p
}
O
E
E
E
/Write
include
-
8/2/2019 Sem 2: Data Structures Practical
14/44
#
i
{
i
b
e
w
{
m
i
r
e
e
eb
}
r
}
m
{
i
i
p
s
pf
s
p
s
p
i
p
e
p
}
O
E
E
E
/Write
include
-
8/2/2019 Sem 2: Data Structures Practical
15/44
#
v
{
}
v
{
}
v
{
}
i
{
i
/Write
include
nt *a, in
p==-1) //
;
]=ITEM;
f(*top==(
(" OVERFL
/Normal c
top+1;
]=ITEM;
t *a, int
p==-1) //
(" UNDERF
op=*top-1
intf("\n
y(int *a,
0;
p!=-1)
top; i>=0
prin
(" NO ELE
("\n");
am to
n, int *
ushing Fi
-1)) //P
W. DELETE
nditions
*top)
Deleting
OW. INSE
;
OPPED...
int top)
; i--)
f("\n %d
ENTS. \n"
mpleme
top, int
rst Eleme
shing int
SOME ELE
from
T SOME EL
\n");
",a[i]);
);
nt Sta
ITEM)
nt
o Filled
ENTS. ");
EMENTS. ")
ks usi
rray
;
g Arra s.
-
8/2/2019 Sem 2: Data Structures Practical
16/44
i
i
i
w
{
}
}
nt n=5; /
nt top=-1;
nt ch=1,I
hile(ch!=
pr
pr
pr
pr
pr
pr
sc
sw
{
}
return 0;
max size
EM;
)
ntf("\n Mntf("\n 1ntf("\n 2ntf("\n 3ntf("\n 4ntf("\n Y
nf("%d",&
tch(ch)
ca
ca
ca
ca
NU: ");
. PUSH. ")
. POP. ");
. DISPLAY.
. EXIT. ")
ur Choice
h);
se 1: //I
prisca
PUS
brea
se 2: //D
POP(
brea
se 3: //D
Dis
brea
se 4: pri
;
");
;
: ");
SERT
tf("\n ENf("%d",&I
(a,n,&top
k;
LETE
a,&top);
k;
SPLAY
lay(a,top
k;
tf(" Exit
TER ITEM:TEM);
, ITEM);
);
ing... ");
");
-
8/2/2019 Sem 2: Data Structures Practical
17/44
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
ENTER ITE
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
ENTER ITE
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
89
56
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
POPPED...
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
56
MENU:
1. PUSH.
2. POP.
3. DISPLA
4. EXIT.
Your Choi
Exiting...
.
e: 1
: 56
.
e: 1
: 89
.
e: 3
.
e: 2
.
e: 3
.
e: 4
-
8/2/2019 Sem 2: Data Structures Practical
18/44
#
v
{
}
v
{
}
v
{
/ Writ
include
t *a, int
g==-1 ) /
g=0;
d=0;
end]=ITEM
( *beg==*
intf("\n
//Normal
d=*end+1;
end]=ITEM
t *a, int
eg==-1 )
intf("\n
f( *beg==
beg=-1;
end=-1;rintf("\n
eg=*beg+1
intf("\n
y(int *a,
("\n");
0;
g!=-1)
beg; i
-
8/2/2019 Sem 2: Data Structures Practical
19/44
}
i
{
i
i
i
i
i
w
{
}
r
}
nt main()
nt a[5];
nt n=5; /
nt beg=-1;
nt end=-1;
nt ch=1,I
hile(ch!=
pr
pr
pr
pr
pr
pr
sc
sw
{
}
eturn 0;
max size
EM;
)
ntf("\n Mntf("\n 1ntf("\n 2ntf("\n 3ntf("\n 4
ntf("\n Y
nf("%d",&
tch(ch)
ca
ca
ca
ca
NU: ");
. INSERT.
. DELETE.
. DISPLAY.
. EXIT. ")
ur Choice
h);
se 1: //I
pri
sca
INS(
brea
se 2: //D
DEL(
brea
se 3: //D
Dis
brea
se 4: pri
");
");
");
;
: ");
SERT
tf("\n EN
f("%d",&I
a,n,&beg,
k;
LETE
a,&beg, &
k;
SPLAY
lay(a,beg
k;
tf("\n Ex
TER ITEM:
TEM);
&end, ITE
end);
,end);
iting... "
");
M);
);
-
8/2/2019 Sem 2: Data Structures Practical
20/44
-
8/2/2019 Sem 2: Data Structures Practical
21/44
#
i
s{
}
i
{
/Write
include
// Total
info;
ct node *
r;
ITEM, in
node * n
e= (struc
e->info=I
e->next=N
OR HANDLI
wnode ==
f(" OVERF
n 0;
OR HANDLI
s
-
8/2/2019 Sem 2: Data Structures Practical
22/44
}
i
{
}
ptr=
newn
ptr-
coun
}
retur
nt DEL(in
struct
//ERRO
if(sta
{
print
retur
}
//ERRO
if( po
{
print
retur
}
// Con
if( po
{
temp=
start
free(
count
}
// Con
else
{
int i;
ptr=s
for(i
ptr=p
temp=ptr->
free(
count
}
return
tr->next;
de->next
next = ne
++;
1; //suc
pos)
node *tem
HANDLING
t == NULL
(" UNDERF
0;
HANDLING
-
8/2/2019 Sem 2: Data Structures Practical
23/44
i
{
}
i
{
nt TRAVER
ptr=sta
// ERRO
if(star
{
printf(
return
}
// TRAV
int i;
printf("
for(i=1;
{
printf(
}
printf("
return
nt main()
int it
int ch,
start=
count=
do
{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
if(sta
{
print
scanf(
}
succes
break;
E()
t;
HANDLING
==NULL)
" Linked
0;
RSING
\n [");
iinfo);
:");
sert a no
ete a no
splay the
IT. \n You
ITEM: ");
);
POSITIO
s);
,pos);
. No Node
=ptr->nex
e. ");
e. ");
Singly Li
r Choice:
: ");
s to disp
t)
nked List.
");
ay. ");
");
-
8/2/2019 Sem 2: Data Structures Practical
24/44
}
case 2:
if(sta
{
print
scanf(
}
succes
break;
case 3:
printf(
succes
break;
case 4:
printf(
break;
defaul
}
}
while(
return
//DELETE
t!=NULL)
("\n ENTE
"%d", &po
=DEL(pos)
//DISPLA
"\n The N
=TRAVERSE
"\n Exiti
: printf(
h!=4); //
0;
POSITIO
s);
;
Y
des: \n")
();
g.. ");
" INVALID
nd of do
: ");
;
CHOICE. "
while loo
);
-
8/2/2019 Sem 2: Data Structures Practical
25/44
O
UTPUT:
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
ENTER ITE
ENTER POS
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
ENTER ITE
ENTER POS
MENU:1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
The Nodes:
[ - 34 -
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
ENTER ITE
ENTER POS
a node.
a node.
the Sing
e: 1
: 34
a node.
a node.
the Sing
e: 1
: 56
TION: 2
a node.
a node.
the Sing
e: 1
: 67
TION: 3
a node.
a node.
the Sing
e: 3
6 - 67 -
a node.
a node.
the Sing
e: 1
: 12
TION: 1
y Linked
y Linked
y Linked
y Linked
]
y Linked
List.
List.
List.
List.
List.
-
8/2/2019 Sem 2: Data Structures Practical
26/44
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
The Nodes:
[ - 12 -
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
ENTER ITE
ENTER POS
Position
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
ENTER POS
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
The Nodes:
[ - 12 -
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT.
Your Choi
Exiting..
a node.
a node.
the Sing
e: 3
4 - 56 -
a node.
a node.
the Sing
e: 1
: 0
TION: 6
ntered is
a node.
a node.
the Sing
e: 2
TION: 3
a node.
a node.
the Sing
e: 3
4 - 67 -
a node.
a node.
the Sing
e: 4
y Linked
67 - ]
y Linked
over lim
y Linked
y Linked
]
y Linked
List.
List.
ts.
List.
List.
List.
-
8/2/2019 Sem 2: Data Structures Practical
27/44
#
i
s
{
}
i
{
/Write
include
info;
ct node*
ct node*
r;
t ITEM, i
node * ne
= (struct
->info=IT
->next=NU->prev=NU
R HANDLIN
ode==NULL
("\n No M
0;
HANDLING
-
8/2/2019 Sem 2: Data Structures Practical
28/44
}
i
{
ptr=p
newno
newno
ptr->
count
}
// Con
else
{
int i;
ptr=s
for(i
ptr=p
newno
newno
(ptr-
ptr->
count
}
return 1;
nt DEL(in
struct
// ERR
if(sta
{
print
retur
}
// ERR
if( po
{
print
retur
}
// Con
if(pos
{
temp=
startfree(
count
}
// Con
else i
{
for(p
(ptr-
r->next;
e->next=p
e->prev=p
ext=newno
+;
ition 4:
art;
2; inext;
e->next=p
e->prev=p
next)->pr
ext=newno
+;
pos)
node *tem
R HANDLIN
t==NULL)
("\n Ther
0;
R HANDLIN
-
8/2/2019 Sem 2: Data Structures Practical
29/44
}i
{
}
i
{
}
i
{
print
free(
count
}
// Con
else
{
int i;
ptr=s
for(i
ptr=p
(ptr-
(ptr-
print
free(
count
}
return
nt F_Trav
if(sta
{
print
retur
}
printf(
for(pt
printf(
printf(
return
nt R_Trav
if(sta
{
print
retur
}
for(pt
printf(for(;
printf(
printf(
return
nt Search(
("\n Dele
tr);
-;
ition 3;
art;
2; inext;
prev)->ne
next)->pr
("\n Dele
tr);
-;
1;
rse()
t==NULL)
("\n Ther
0;
"\n [");
=start; p
" - %d",p
" - ]\n")
1;
rse()
t==NULL)
("\n Ther
0;
=start; p
"\n [");tr!=NULL;
" - %d",p
" - ]\n")
1;
int ITEM)
ing Node
eleting
; i++)
t=ptr->ne
v=ptr->p
ing Node
are no e
r!=NULL;
r->info);
;
are no e
r->next!
ptr=ptr->
r->info);
;
with valu
ode at an
xt;
ev;
with valu
lements i
ptr=ptr->
lements i
NULL; ptr
prev)
e = %d" ,
other p
e = %d",pt
n this Li
next)
n this Li
=ptr->next
ptr->info
sition
r->info);
ked List.
ked List.
);
);
");
");
-
8/2/2019 Sem 2: Data Structures Practical
30/44
}
i
{
int i;
for(i=
if(ptr
return
return
nt main()
int ch,
int IT
start=
count=
do
{
printf(
printf(
printf(printf(
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
,ptr=star
>info==IT
i;
-1;
success;
M; int po
ULL;
;
"\n _____"\n MENU:
"\n\n 1."\n 2. De"\n 3. Fo"\n 4. Re"\n 5. Se"\n 0. EX"\n\n You
%d", &ch)
ch)
case 1
printf
scanf(
if(sta
{
printf
scanf(
}
succes
break;
case 2
if(sta{
printf
scanf(
}
succes
break;
case 3
printf
; ptr!=N
M)
s=1;
________
");
Insert aete a No
ward Tra
erse Tra
rch for
IT. ");
Choice:
;
: //INSER
("\n Ente
"%d",&ITE
t!=NULL)
("\n Ente
"%d", &pos
s=INS(ITE
: //DELET
t!=NULL)
("\n Ente
"%d", &pos
s=DEL(pos)
: //Forwa
("\n The E
LL; ptr=p
_________
ode. ");e. ");
ersing th
ersing th
node. ")
");
the Item
);
the posi
);
, pos);
the posi
);
;
d Travers
lements:
tr->next,
________
e Doubly
e Doubly
;
to Insert
tion: ");
tion: ");
ing
");
++)
_________
L. ");
L. ");
: ");
_______ ");
-
8/2/2019 Sem 2: Data Structures Practical
31/44
}
}
}while(
retur
succes
break;
case 4
printf
succes
break;
case 5
printf
scanf(
pos=Se
if(pos
printf
else
printf
break;
case 0
printf
ch);
1;
s=F_Trave
: //Rever
("\n The E
s=R_Trave
: //Searc
("\n Ente
"%d",&ITE
rch(ITEM)
!=-1)
("\n The I
("\n Item
:
("\n Exit
se();
e Travers
lements:
se();
ing
the Item
);
;
tem is fo
not found
ng... ");
ing
\n");
to Searc
und at %d
. ");
for: ");
Position",pos);
-
8/2/2019 Sem 2: Data Structures Practical
32/44
O
_
UTPUT:_________
MENU:
1. Insert
2. Delete3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
Enter the
_________
MENU:
1. Insert2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
Enter the
Enter the
_________
MENU:
1. Insert
2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
Enter the
Enter the
_________
a Node.
a Node.Traversi
Traversi
for a nod
e: 1
Item to I
_________
a Node.a Node.
Traversi
Traversi
for a nod
e: 1
Item to I
position:
_________
a Node.
a Node.
Traversi
Traversi
for a nod
e: 1
Item to I
position:
________
g the Dou
g the Dou
.
sert: 23
________
g the Dou
g the Dou
.
sert: 12
1
________
g the Dou
g the Dou
.
sert: 90
3
_________
bly LL.
bly LL.
_________
bly LL.
bly LL.
_________
bly LL.
bly LL.
________
________
________
__
___
___
-
8/2/2019 Sem 2: Data Structures Practical
33/44
_
_________
MENU:
1. Insert
2. Delete
3. Forwar4. Revers
5. Search
0. EXIT.
Your Choi
The Eleme
[ - 12 -
_________
MENU:
1. Insert
2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
The Eleme
[ - 90 -
_________
MENU:
1. Insert
2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
Enter the
The Item
_________
a Node.
a Node.
TraversiTraversi
for a nod
e: 3
ts:
3 - 90 -
_________
a Node.
a Node.
Traversi
Traversi
for a nod
e: 4
ts:
3 - 12 -
_________
a Node.
a Node.
Traversi
Traversi
for a nod
e: 5
Item to S
s found a
________
g the Doug the Dou
.
]
________
g the Dou
g the Dou
.
]
________
g the Dou
g the Dou
.
arch for:
1 Posit
_________
bly LL.bly LL.
_________
bly LL.
bly LL.
_________
bly LL.
bly LL.
12
on
________
________
________
__
___
___
-
8/2/2019 Sem 2: Data Structures Practical
34/44
_
_________
MENU:
1. Insert
2. Delete
3. Forwar4. Revers
5. Search
0. EXIT.
Your Choi
Enter the
_________
MENU:
1. Insert
2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
The Eleme
[ - 23 -
_________
MENU:
1. Insert2. Delete
3. Forwar
4. Revers
5. Search
0. EXIT.
Your Choi
Exiting...
_________
a Node.
a Node.
TraversiTraversi
for a nod
e: 2
position:
_________
a Node.
a Node.
Traversi
Traversi
for a nod
e: 3
ts:
0 - ]
_________
a Node.a Node.
Traversi
Traversi
for a nod
e: 0
________
g the Doug the Dou
.
1
________
g the Dou
g the Dou
.
________
g the Dou
g the Dou
.
_________
bly LL.bly LL.
_________
bly LL.
bly LL.
_________
bly LL.
bly LL.
________
________
________
__
___
___
-
8/2/2019 Sem 2: Data Structures Practical
35/44
a
#
v
{
}
i{
/ Writ
nd Mul
include
-
8/2/2019 Sem 2: Data Structures Practical
36/44
}
O
c[i][j]
printf(
Matrix
//Mult
for(i=
for(j=
{
c[i][
for(k
c[i][
}
printf(
Matrix
UTPUT:
Enter the
Enter ele
Enter ele
Matrix A:
1 2
3 4
Matrix B:4 3
2 1
Addition
5 5
5 5
Subtracti
-3 -1
1 3
Multiplic
8 5
20 13
=a[i][j]-
"\n\n Sub
Display(c
plication
; i
-
8/2/2019 Sem 2: Data Structures Practical
37/44
#
s
{
}
v
{
s
n
i
p
e
{
n
i
{
n
t
}
e
{
n
t
}
}
}
v
{
i
p
e
{
p
t
t
f
}
}
v
{
i
p
e
/WAP t
include
info;ct node *
;
nt item)
*newnode
struct no
=NULL)
SPACE LE
fo=item;
NULL )
xt=NULL;
;
xt=top;
;
outer els
func
L)
Stack Emp
Node with
xt;
Y()
L)
Stack is
ent St
next;
;
e *) mal
T ");
y. \n");
Info=%d
mpty. ");
cks us
oc ( size
s deleted
ing Li
of(struct
. \n", to
ked Li
node) );
->info);
ts.
-
8/2/2019 Sem 2: Data Structures Practical
38/44
{
t
p
w
{
p
t
}
p
}
}
i
{
emp=top;
rintf("\n"
hile(temp!
rintf("\n
emp=temp-
rintf("\n"
//end of
nt main()
int it
top=NU
while(c{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
PUSH(i
break;
case 2:
POP();
break;
case 3:
DISPLA
break;
case 4:printf(
break;
defaul
}
}; //e
return
);
=NULL)
|%d| ", t
next;
);
lse
m,ch=1;
L;
!=4)
"\n MENU:"\n 1. In"\n 2. De"\n 3. Di"\n 4. EX
%d",&ch);
ch)
//INSERT
"\n ENTER
%d", &ite
em);
//DELETE
//DISPLA
();
"\n Exiti
: printf(
d of whil
0; }
mp->info)
");
sert a no
ete a no
splay Stac
IT \n You
ITEM: ");
);
Y
g.. ");
" INVALID
loop
;
e. ");
e. ");
k. ");
Choice:
CHOICE. "
");
);
-
8/2/2019 Sem 2: Data Structures Practical
39/44
O
M
UTPUT:
ENU:
1. Insert
2. Delete3. Displa
4. EXIT
Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete3. Displa
4. EXIT
Your Choi
|90|
|89|
|64|
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
Node with
a node.
a node.Stack.
e: 1
: 64
a node.
a node.
Stack.
e: 1
: 89
a node.
a node.
Stack.
e: 1
: 90
a node.
a node.Stack.
e: 3
a node.
a node.
Stack.
e: 2
Info=90 is deleted.
-
8/2/2019 Sem 2: Data Structures Practical
40/44
M
ENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
|89|
|64|
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
Exiting..
a node.
a node.
Stack.
e: 2
a node.
a node.
Stack.
e: 4
-
8/2/2019 Sem 2: Data Structures Practical
41/44
#
s
{
}
v
{
s
n
i
p
e
{n
n
i
{
s
r
}
e
{
r
r
}
}
}
v
{
i
p
e
{
p
ts
f
}
}
/ WAP
includeinf
sts.
);
-
8/2/2019 Sem 2: Data Structures Practical
42/44
v
{
i
p
e
{
t
p
w
{
p
t
}
p
}
}
i
{
oid DISPL
f(start==
rintf("\n
lse
emp=start;
rintf("\n
hile(temp!
rintf(" -
emp=temp-
rintf(" -
//end of
nt main()
int it
start=
while(c
{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
INS(it
break;
case 2:
DEL();
break;
case 3:
DISPLA
break;
case 4:printf(
break;
defaul
}
}; //
retur
Y()
ULL)
Queue is
|");
=NULL)
|%d|", te
next;
| \n");
lse
m,ch=1;
ear=NULL;
!=4)
"\n MENU:
" 1. Inse
"\n 2. De"\n 3. Di"\n 4. EX
%d",&ch);
ch)
//INSERT
"\n ENTER
%d", &ite
m);
//DELETE
//DISPLA
();
"\n Exiti
: printf(
nd of whi
0; }
mpty. No
p->info);
\n");
t a node.
ete a no
splay Queu
IT \n You
ITEM: ");
);
Y
g.. ");
" INVALID
e loop
Nodes. ")
");
e. ");
e. ");
Choice:
CHOICE. "
;
");
);
-
8/2/2019 Sem 2: Data Structures Practical
43/44
O
M
UTPUT:
ENU:
1. Insert
2. Delete
3. Displa
4. EXITYour Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
ENTER ITE
MENU:
1. Insert
2. Delete
3. Displa
4. EXITYour Choi
| - |64|
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
Node with
MENU:
1. Insert
2. Delete
3. Displa
4. EXIT
Your Choi
| - |89|
a node.
a node.
Queue.
e: 1
: 64
a node.
a node.
Queue.
e: 1
: 89
a node.
a node.
Queue.
e: 1
: 90
a node.
a node.
Queue.
e: 3
|89| - |
a node.
a node.
Queue.
e: 2
Info = 64
a node.
a node.
Queue.
e: 3
|90| - |
90| - |
is Delete
d.
-
8/2/2019 Sem 2: Data Structures Practical
44/44
NEIL
A23
2CS
ATH
47100
Y33
W
2
5