2.
C
1
2
3
4
5
6
7
8
9
1
1
1
1
1
CONTE
1. Writ
Dele
2. WAP
3. WAP
4. WAP
5. WAP
6. WAP
7. WAP
8. WAP
9. WAP
10. WAP
11. WAP
12. WAP
on 2
13. WAP
14. WAP
ENTS
te a Progr
etion, Sea
P to perfo
P to perfo
P to perfo
P to perfo
P to perfo
P to perfo
P to imple
P to imple
P to imple
P to imple
P to perfo
2 Two‐Dim
P to imple
P to imple
ram using
rching, So
orm Bubb
orm Selec
orm Inser
orm Merg
orm Linea
orm Binar
ement Sta
ement Qu
ement Sin
ement Do
orm Addit
mensiona
ement Sta
ement Qu
g Arrays p
orting an
ble Sort.
ction Sort
tion Sort
ge Sort.
ar Search.
ry Search
acks using
ueues usi
ngly Linke
oubly Link
tion, Subt
l Array.
acks using
ueues usi
performin
d Travers
t.
.
.
.
g Arrays.
ng Arrays
ed Lists.
ked Lists.
traction a
g Linked
ng Linked
ng Insertio
sing Oper
s.
and Multi
Lists.
d Lists.
on,
rations.
iplication
3.
/
I
T
#i
in
in
{
}
vo
{
}
vo
{
// Write
Insertio
Traversi
include <s
nt n; //si
nt BSearch
int beg
int mid
while(
{
mid=(b
if(a[m
return
else i
beg=mi
else
end=mi
}
return
oid SSort(
int i,j
for(i=0
{
for(j=
{
if(a[
{
temp
a[i]
a[j]
}
}
}
oid DEL(in
int i;
int po
if(pos
{
e a Prog
on, Dele
ing Oper
stdio.h>
ize of arra
h(int *a,in
g=0,end=n-1
d;
beg<=end )
beg+end)/2;
mid]==ITEM)
n mid;
if( a[mid]
id+1;
id-1;
-1;
(int *a)
j,temp;
0; i<n-1; i
=i+1; j<n;
[i]>a[j])
p=a[i];
=a[j];
=temp;
nt *a, int
;
os=BSearch(
s!=-1)
gram usi
etion, S
rations.
ay
nt ITEM)
1;
)
;
)
< ITEM )
i++)
j++)
ITEM)
(a, ITEM);
ing Arra
Searchin
.
rays per
ng, Sor
rforming
rting an
g
nd
4.
}
vo
{
}
vo
{
}
in
{
{
for(i=
a[i]=a
n--;
printf
}
else
printf
oid INS(in
int po
//Find
if(ITE
pos=n;
else i
pos=0;
else
{
fo
if
{
p
b
}
}
//Shif
for(i=
a[i]=a
a[pos]
n++;
printf
oid Displa
int i
for(i
print
nt main()
int a[1
printf(
scanf("
printf(
for(i=0
scanf("
do
=pos; i<n-1
a[i+1];
f("n Item
f("n Item
nt *a, int
os,i;
ding the pr
EM>a[n-1])
;
if(ITEM<a[0
;
or(i=0; i<n
f(a[i]<=ITE
pos=i+1;
break;
fting of el
=n; i>pos;
a[i-1];
=ITEM;
f("n Item
ay(int *a)
i;
i=0; i<n; i
tf(" %d",a[
100],ch,pos
("n Enter
"%d",&n);
("n Enter
0; i<n; i++
"%d",&a[i])
1; i++)
Deleted.
not found
ITEM)
roper posi
0])
n-1; i++)
EM && a[i+
lements to
i--)
Inserted.
i++)
[i]);
s,ITEM,i;
the numbe
the Eleme
+)
);
");
d. ");
ition for S
+1]>=ITEM)
o Insert th
");
er of Eleme
ents: ");
Sorted Arr
he element
ents: ");
ray
t.
6.
}
OU
E
E
_
M
1
2
3
4
0
Y
T
_
M
1
2
3
4
0
Y
E
I
_
M
1
2
3
4
0
Y
E
I
print
break
}
}whil
UTPUT:
Enter the
Enter the
__________
MENU:
1. Insert
2. Delete
3. Search
4. Display
0. Exit.
Your Choic
The Elemen
__________
MENU:
1. Insert
2. Delete
3. Search
4. Display
0. Exit.
Your Choic
Enter the
Item Inser
__________
MENU:
1. Insert
2. Delete
3. Search
4. Display
0. Exit.
Your Choic
Enter the
Item found
tf("n Exit
k;
le(ch!=0);
number of
Elements:
___________
an element
an element
for an ele
y elements.
ce: 4
nts are: 2
___________
an element
an element
for an ele
y elements.
ce: 1
Item to In
rted. 2 4
___________
an element
an element
for an ele
y elements.
ce: 3
Item to Se
d at 5 posi
ting... ")
Elements:
10 2 8 4
__________
t.
t.
ement.
.
2 4 6 8 10
__________
t.
t.
ement.
.
nsert: 7
6 7 8 10
__________
t.
t.
ement.
.
earch: 8
ition.
;
5
6
__________
0
__________
__________
7.
_
M
1
2
3
4
0
Y
E
I
_
M
1
2
3
4
0
Y
E
__________
MENU:
1. Insert
2. Delete
3. Search
4. Display
0. Exit.
Your Choic
Enter the
Item Delet
__________
MENU:
1. Insert
2. Delete
3. Search
4. Display
0. Exit.
Your Choic
Exiting...
___________
an element
an element
for an ele
y elements.
ce: 2
Item to De
ted. 2 6 7
___________
an element
an element
for an ele
y elements.
ce: 0
.
__________
t.
t.
ement.
.
elete: 4
7 8 10
__________
t.
t.
ement.
.
__________
__________
8.
/
#i
vo
{
in
fo
fo
if
{
te
a[
a[
}
}
ma
{
in
pr
sc
pr
fo
sc
Bs
pr
fo
pr
}
O
En
En
El
2
// Write
include<st
oid Bsort(
nt i,j,tem
or(i=n-1;
or(j=0; j<
f(a[j]>a[j
emp=a[j+1]
[j+1]=a[j]
[j]=temp;
ain()
nt a[50],n
rintf("Ent
canf("%d",
rintf("Ent
or(i=0; i<
canf("%d",
sort(a,n);
rintf("nE
or(i=0; i<
rintf("%d
OUTPUT:
nter size
nter eleme
lements:
4 5 6 8
e A Prog
tdio.h>
(int *a,int
mp;
i>=0; i--)
<i; j++)
j+1])
;
;
n,i;
ter size of
&n);
ter element
<n; i++)
&a[i]);
;
Elements:
<n; i++)
",a[i]);
of your ar
ents of you
gram to
t n)
)
f your arr
ts of your
n");
rray: 5
ur array:
perform
ray: ");
r array: ")
2 8 4 6 5
rm a bub
);
bble sorrt.
9.
/
#i
vo
{
in
fo
fo
if
{
te
a[
a[
}
}
ma
{
in
pr
sc
pr
fo
sc
Ss
pr
fo
pr
}
OU
En
En
El
1
//Write
include<st
oid Ssort(
nt i,j,tem
or(i=0; i<
or(j=i+1;
f(a[i]>a[j
emp=a[i];;
[i]=a[j];
[j]=temp;
ain()
nt a[50],n
rintf("Ent
canf("%d",
rintf("Ent
or(i=0; i<
canf("%d",
sort(a,n);
rintf("nE
or(i=0; i<
rintf("%d
UTPUT:
nter size
nter eleme
lements:
3 6 7 9
A Progr
tdio.h
(int *a,int
mp;
<n-1; i++)
j<n; j++)
j])
;
n,i;
ter size of
&n);
ter element
<n; i++)
&a[i]);
;
Elements:
<n; i++)
",a[i]);
of your ar
ents of you
ram to p
t n)
f your arr
ts of your
n");
rray: 5
ur array:
perform
ray: ");
r array: ")
1 9 3 7 6
m a sele
);
ection ssort.
10.
/
#i
vo
{
in
a[
fo
{
te
fo
{
a[
}
a[
}
}
ma
{
in
pr
sc
pr
fo
sc
Is
pr
fo
pr
}
OU
En
En
El
2
//Write
include<st
oid Isort(
nt i,j,tem
[0]=-99;
or(i=2; i<
emp=a[i];
or(j=i-1;
[j+1]=a[j]
[j+1]=temp
ain()
nt a[50],n
rintf("Ent
canf("%d",
rintf("Ent
or(i=1; i<
canf("%d",
sort(a,n);
rintf("nE
or(i=1; i<
rintf("%d
UTPUT:
nter size
nter eleme
lements:
4 5 6 8
A Progr
tdio.h>
(int *a,int
mp;
<n+1; i++)
temp < a[j
;
p;
n,i;
ter size of
&n);
ter element
<n+1; i++)
&a[i]);
;
Elements:
<n+1; i++)
",a[i]);
of your ar
ents of you
ram to p
t n)
j]; j--)
f your arr
ts of your
n");
rray: 5
ur array:
perform
ray: ");
r array: ")
2 8 4 6 5
m an Ins
);
sert sorrt.
11.
/
#i
vo
{
}
in
{
// Write
include<st
oid MergeS
int i=
while(
{
}
if( i<
{
wh
c[
}
else i
{
w
c
}
nt main()
int a[5
int i,m
printf(
scanf("
printf(
for(i=0
scanf("
printf(
scanf("
printf(
for(i=0
scanf("
MergeSo
e a prog
tdio.h>
Sort(int *a
=0,j=0,k=0;
( i<m && j<
if( a[i]
{
c[k++
}
else
{
c[k++
}
<m )
hile( i<m )
[k++]=a[i++
if( j<n )
while(j<n)
c[k++]=a[j+
50],b[50],c
m,n;
("n Enter
"%d",&m);
("n Enter
0; i<m; i++
"%d",&a[i])
("n Enter
"%d",&n);
("n Enter
0; i<n; i++
"%d",&b[i])
ort(a,m,b,n
gram to
a, int m,
;
<n)
<= b[j] )
+]=a[i++];
+]=b[j++];
)
+];
++];
c[100];
the Size
the Eleme
+)
);
the Size
the Eleme
+)
);
n,c);
perform
int *b, in
of Array A
ents (In As
of Array B
ents (In As
rm Merge
nt n, int
A: ");
scending O
B: ");
scending O
e Sort.
*c)
Order) : ")
Order) : ")
);
);
12.
}
OU
E
E
E
E
T
printf(
for(i=0
printf(
UTPUT:
Enter the
Enter the
Enter the
Enter the
The Merged
("n The Me
0; i<(m+n);
(" %d",c[i]
Size of Ar
Elements (
Size of Ar
Elements (
d & Sorted
erged & So
; i++)
]);
rray A: 6
(In Ascend
rray B: 5
(In Ascend
Array C:
orted Array
ding Order)
ding Order)
0 1 2 3 4
y C: ");
) : 0 2 4
) : 1 3 5
4 5 6 7 8
6 8 10
7 9
9 10
13.
/
#i
in
{
in
fo
{
if
re
}
re
}
ma
{
in
in
pr
sc
pr
fo
sc
pr
sc
po
if
pr
el
pr
}
OU
En
En
En
F
//Write
include<st
nt Lsearch
nt i;
or(i=0; i<
f(item==a[
eturn i;
eturn -1;
ain()
nt a[50],n
nt item,po
rintf("Ent
canf("%d",
rintf("Ent
or(i=0; i<
canf("%d",
rintf("Ent
canf("%d",
os=Lsearch
f(pos==-1)
rintf(" NO
lse
rintf(" FO
UTPUT:
nter size
nter eleme
nter item
FOUND AT 4
a progr
tdio.h>
h(int *a, i
<n; i++)
[i])
n,i;
os;
ter size of
&n);
ter element
<n; i++)
&a[i]);
ter item to
&item);
h(a,n,item)
OT FOUND. "
OUND AT %d"
of your ar
ents of you
to search:
4
ram to p
int n, int
f your arr
ts of your
o search:
);
");
", (pos+1)
rray: 5
ur array:
: 4
perform
t item)
ray: ");
r array: ")
");
);
0 1 3 4 6
m Linear
);
r Searchh.
14.
/
#i
in
{
in
be
en
wh
{
mi
if
re
el
en
el
be
}
re
}
ma
{
in
in
pr
sc
pr
fo
sc
pr
sc
po
if
pr
el
pr
}
OU
En
En
En
F
//Write
include<st
nt Bsearch
nt beg,end
eg=0;
nd=n-1;
hile(beg<=
id=(beg+en
f(a[mid]==
eturn mid;
lse if(a[m
nd=mid-1;
lse if(a[m
eg=mid+1;
eturn -1;
ain()
nt a[50],n
nt item,po
rintf("Ent
canf("%d",
rintf("Ent
or(i=0; i<
canf("%d",
rintf("Ent
canf("%d",
os=Bsearch
f(pos==-1)
rintf(" NO
lse
rintf(" FO
UTPUT:
nter size
nter eleme
nter item
FOUND AT 5
A Progr
tdio.h>
h(int *a, i
d,mid;
=end)
nd)/2;
=item)
;
mid]>item)
mid]<item)
n,i;
os;
ter size of
&n);
ter element
<n; i++)
&a[i]);
ter item to
&item);
h(a,n,item)
OT FOUND. "
OUND AT %d"
of your ar
ents of you
to search:
5
ram to p
int n, int
f your arr
ts of your
o search:
);
");
", (pos+1)
rray: 6
ur array:
: 10
perform
t item)
ray: ");
r array: ")
");
);
2 4 6 8 10
m Binary
);
0 13
y Searchh.
15.
/
#i
vo
{
}
vo
{
}
vo
{
}
in
{
in
//Write
include<st
oid PUSH(i
if(*to
{
*top=0
a[*top
}
else i
{
printf
}
else /
{
*top=*
a[*top
}
oid POP(in
if(*to
{
printf
}
else
{
*t
pr
}
oid Displa
int i=
if (to
for(i=
{
}
else
printf
printf
nt main()
nt a[5];
A Progr
tdio.h>
int *a, int
op==-1) //P
0;
p]=ITEM;
if(*top==(n
f(" OVERFLO
//Normal co
*top+1;
p]=ITEM;
nt *a, int
op==-1) //
f(" UNDERFL
top=*top-1;
rintf("n P
ay(int *a,
=0;
op!=-1)
=top; i>=0;
print
f(" NO ELEM
f("n");
ram to i
t n, int *
Pushing Fi
n-1)) //Pu
OW. DELETE
onditions
*top)
Deleting
LOW. INSER
;
POPPED...
int top)
; i--)
tf("n %d
MENTS. n"
implemen
*top, int I
irst Elemen
ushing into
E SOME ELEM
from
RT SOME ELE
n");
",a[i]);
");
nt Stac
ITEM)
nt
o Filled a
MENTS. ");
EMENTS. ")
cks usin
array
;
ng Arrayys.
16.
in
in
in
wh
{
}
}
nt n=5; //
nt top=-1;
nt ch=1,IT
hile(ch!=4
pri
pri
pri
pri
pri
pri
sca
swi
{
}
return 0;
/max size
;
TEM;
4)
intf("n ME
intf("n 1.
intf("n 2.
intf("n 3.
intf("n 4.
intf("n Yo
anf("%d",&c
itch(ch)
cas
cas
cas
cas
;
ENU: ");
. PUSH. ")
. POP. ");
. DISPLAY.
. EXIT. ")
our Choice
ch);
se 1: //IN
prin
scan
PUSH
brea
se 2: //DE
POP(
brea
se 3: //DI
Disp
brea
se 4: prin
;
");
;
e: ");
NSERT
ntf("n ENT
nf("%d",&IT
H(a,n,&top,
ak;
ELETE
(a,&top);
ak;
ISPLAY
play(a,top)
ak;
ntf(" Exiti
TER ITEM:
TEM);
, ITEM);
);
ing... ");
");
17.
M
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
8
5
M
1
2
3
4
Y
P
M
1
2
3
4
Y
5
M
1
2
3
4
Y
E
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
ENTER ITEM
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
ENTER ITEM
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
89
56
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
POPPED...
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
56
MENU:
1. PUSH.
2. POP.
3. DISPLAY
4. EXIT.
Your Choic
Exiting...
Y.
ce: 1
M: 56
Y.
ce: 1
M: 89
Y.
ce: 3
Y.
ce: 2
Y.
ce: 3
Y.
ce: 4
.
18.
/
#i
vo
{
}
vo
{
}
vo
{
// Write
include <s
oid INS(in
if( *be
{
*be
*en
a[*
}
else if
{
pr
}
else
{
*en
a[*
}
oid DEL(in
if( *b
{
pr
}
else i
{
*
*
p
}
else
{
*b
pr
}
oid Displa
printf
int i=
if (be
for(i=
{
}
else
printf
printf
e a Prog
stdio.h>
nt *a, int
eg==-1 ) //
eg=0;
nd=0;
*end]=ITEM;
f( *beg==*e
rintf("n O
//Normal S
nd=*end+1;
*end]=ITEM;
nt *a, int
beg==-1 )
rintf("n U
if( *beg==*
*beg=-1;
*end=-1;
printf("n
beg=*beg+1;
rintf("n E
ay(int *a,
f("n");
=0;
eg!=-1)
=beg; i<=en
print
f("n NO EL
f("n");
gram to
n, int *b
/FIRST ELE
;
end+1 || (
OVERFLOW.
Situations
;
*beg, int
UNDERFLOW,
*end ) //L
Element D
;
Element De
int beg,
nd; i++)
tf(" %d ",
LEMENTS.
impleme
beg, int *e
EMENT
( *beg==0 &
DELETE SOM
s
t *end)
ADD SOME
LAST ELEMEN
Deleted. n
eleted.n")
int end)
a[i]);
n");
ment Que
end, int I
&& *end==(
ME ELEMENT
ELEMENTS:
NT
n");
);
eues usi
ITEM)
(n-1) ) ) /
TS: ");
");
ing Arra
//OVERFLOW
ays
W
19.
}
in
{
in
in
in
in
in
wh
{
}
re
}
nt main()
nt a[5];
nt n=5; //
nt beg=-1;
nt end=-1;
nt ch=1,IT
hile(ch!=4
pri
pri
pri
pri
pri
pri
sca
swi
{
}
eturn 0;
/max size
;
;
TEM;
4)
intf("n ME
intf("n 1.
intf("n 2.
intf("n 3.
intf("n 4.
intf("n Yo
anf("%d",&c
itch(ch)
cas
cas
cas
cas
ENU: ");
. INSERT.
. DELETE.
. DISPLAY.
. EXIT. ")
our Choice
ch);
se 1: //IN
prin
scan
INS(
brea
se 2: //DE
DEL(
brea
se 3: //DI
Disp
brea
se 4: prin
");
");
");
;
e: ");
NSERT
ntf("n ENT
nf("%d",&IT
(a,n,&beg,
ak;
ELETE
(a,&beg, &e
ak;
ISPLAY
play(a,beg,
ak;
ntf("n Exi
TER ITEM:
TEM);
&end, ITE
end);
,end);
iting... "
");
EM);
");
20.
M
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
2
M
1
2
3
4
Y
E
M
1
2
3
4
Y
5
M
1
2
3
4
Y
E
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
ENTER ITEM
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
ENTER ITEM
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
24 56
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
Element De
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
56
MENU:
1. INSERT.
2. DELETE.
3. DISPLAY
4. EXIT.
Your Choic
Exiting...
.
.
Y.
ce: 1
M: 24
.
.
Y.
ce: 1
M: 56
.
.
Y.
ce: 3
.
.
Y.
ce: 2
eleted.
.
.
Y.
ce: 3
.
.
Y.
ce: 4
.
21.
/
#i
in
st
{
}*
in
{
//Write
include<st
nt count;
truct node
int
stru
*start,*pt
nt INS(int
struct
newnod
newnod
newnod
// ERR
if( ne
{
print
retur
}
// ERR
if( po
{
print
retur
}
// Con
if( st
{
start
count
}
// Con
else i
{
newno
start
count
}
// Con
else
{
int i
ptr=s
for(i
a Progr
tdio.h>
// Total n
e
info;
uct node *
tr;
t ITEM, int
t node * ne
de= (struct
de->info=IT
de->next=NU
ROR HANDLIN
ewnode == N
tf(" OVERFL
rn 0;
ROR HANDLIN
os<=0 || po
tf(" Positi
rn 0;
ndition 1:
tart==NULL
t=newnode;
t=1;
ndition 2:
if( pos==1)
ode->next=s
t=newnode;
t++;
ndition 3:
i;
start;
i=2; i<=pos
ram to i
number of
next;
t pos)
ewnode;
t node *)
TEM;
ULL;
NG #1 - No
NULL )
LOW: No Me
NG #2 - Po
os>count+1
ion entere
First nod
)
Adding no
)
start;
Adding no
s-1; i++)
implemen
nodes in S
malloc ( s
o Memory Le
emory Left
osition Ove
1 )
ed is over
de of LL
ode to firs
ode to any
nt Sing
Singly Lin
sizeof(str
eft (Overf
to create
er Limits
limits. "
st positio
other pos
gly Link
nked List.
ruct node)
flow)
e newnode.
");
on of LL
sition of L
ked List
) ;
");
LL
ts.
22.
}
in
{
}
ptr=p
newno
ptr->
count
}
return
nt DEL(int
struct
//ERROR
if(star
{
printf
return
}
//ERROR
if( pos
{
printf
return
}
// Cond
if( pos
{
temp=s
start=
free(t
count-
}
// Cond
else
{
int i;
ptr=st
for(i=
ptr=pt
temp=p
ptr->n
free(t
count-
}
return
ptr->next;
ode->next =
>next = new
t++;
n 1; //succ
t pos)
node *temp
R HANDLING
rt == NULL)
f(" UNDERFL
n 0;
R HANDLING
s<=0 || pos
f(" Positio
n 0;
dition 1: D
s==1 )
start;
=start->nex
temp);
--;
dition 2: D
;
tart;
=2; i<=pos-
tr->next;
ptr->next;
next=temp->
temp);
--;
1;
= ptr->nex
wnode;
cessful
p;
#1 - Unde
)
LOW: No No
#2 - Posi
s>count )
on entered
Deleting F
xt;
Deleting a
-1; i++)
>next;
xt;
erflow
ode left to
ition Over
d is over l
First Node
any other n
o delete.
Limits
limits. ")
OR Last R
node
");
;
Remaining NNode
23.
in
{
}
in
{
nt TRAVERS
ptr=star
// ERROR
if(start
{
printf(
return
}
// TRAVE
int i;
printf("
for(i=1;
{
printf(
}
printf("
return 1
nt main()
int ite
int ch,
start=N
count=0
do
{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
if(star
{
printf
scanf(
}
success
break;
SE()
rt;
R HANDLING
t==NULL)
(" Linked L
0;
ERSING
"n [");
; i<=count;
(" - %d",pt
" - ]");
1;
em,pos=1;
success;
NULL;
0;
("nn MENU
("n 1. Ins
("n 2. Del
("n 3. Dis
("n 4. EXI
"%d",&ch);
(ch)
: //INSERT
("n ENTER
"%d", &item
rt!=NULL)
f("n ENTER
("%d", &pos
s=INS(item,
List Empty
; i++, ptr
tr->info);
U:");
sert a nod
lete a nod
splay the
IT. n You
ITEM: ");
m);
R POSITION
s);
,pos);
y. No Nodes
r=ptr->next
de. ");
de. ");
Singly Lin
ur Choice:
N: ");
s to displ
t)
nked List.
");
lay. ");
");
24.
}
case 2:
if(star
{
printf
scanf(
}
success
break;
case 3:
printf(
success
break;
case 4:
printf(
break;
default
}
}
while(c
return
: //DELETE
rt!=NULL)
f("n ENTER
("%d", &pos
s=DEL(pos);
: //DISPLAY
("n The No
s=TRAVERSE(
:
("n Exitin
t: printf("
ch!=4); //e
0;
R POSITION
s);
;
Y
odes: n")
();
ng.. ");
" INVALID
end of do
N: ");
;
CHOICE. ")
while loop
);
p
25.
O
M
1
2
3
4
Y
E
M
1
2
3
4
Y
E
E
M
1
2
3
4
Y
E
E
M
1
2
3
4
Y
T
[
M
1
2
3
4
Y
E
E
OUTPUT:
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER ITEM
ENTER POSI
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER ITEM
ENTER POSI
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
The Nodes:
[ - 34 - 5
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER ITEM
ENTER POSI
a node.
a node.
y the Singl
ce: 1
M: 34
a node.
a node.
y the Singl
ce: 1
M: 56
ITION: 2
a node.
a node.
y the Singl
ce: 1
M: 67
ITION: 3
a node.
a node.
y the Singl
ce: 3
:
56 - 67 - ]
a node.
a node.
y the Singl
ce: 1
M: 12
ITION: 1
ly Linked
ly Linked
ly Linked
ly Linked
]
ly Linked
List.
List.
List.
List.
List.
26.
M
1
2
3
4
Y
T
[
M
1
2
3
4
Y
E
E
P
M
1
2
3
4
Y
E
M
1
2
3
4
Y
T
[
M
1
2
3
4
Y
E
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
The Nodes:
[ - 12 - 3
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER ITEM
ENTER POSI
Position e
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
ENTER POSI
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
The Nodes:
[ - 12 - 3
MENU:
1. Insert
2. Delete
3. Display
4. EXIT.
Your Choic
Exiting..
a node.
a node.
y the Singl
ce: 3
:
34 - 56 - 6
a node.
a node.
y the Singl
ce: 1
M: 0
ITION: 6
entered is
a node.
a node.
y the Singl
ce: 2
ITION: 3
a node.
a node.
y the Singl
ce: 3
:
34 - 67 - ]
a node.
a node.
y the Singl
ce: 4
ly Linked
67 - ]
ly Linked
over limi
ly Linked
ly Linked
]
ly Linked
List.
List.
its.
List.
List.
List.
27.
/
#i
in
st
{
}*
in
{
//Write
include <s
nt count;
truct node
int
stru
stru
*start,*pt
nt INS( in
struct
newnode
newnode
newnode
newnode
// ERRO
if(newn
{
printf
return
}
//ERROR
if( pos
{
printf
return
}
// Cond
if(star
{
start=
count=
}
// Cond
else if
{
newnod
start-
start=
count+
}
// Cond
else if
{
int i;
ptr=st
for(i=
a Progr
stdlib.h>
e
info;
uct node* n
uct node* p
tr;
nt ITEM, in
node * new
e= (struct
e->info=ITE
e->next=NUL
e->prev=NUL
OR HANDLING
node==NULL)
f("n No Me
n 0;
R HANDLING
s<=0 || pos
f("n Posit
n 0;
dition 1: E
rt==NULL)
=newnode;
=1;
dition 2: E
f(pos==1)
de->next=st
->prev=newn
=newnode;
++;
dition 3: E
f(pos==coun
;
tart;
=2; i<=pos-
ram to i
next;
prev;
nt pos)
wnode;
node*) ma
EM;
LL;
LL;
G #1 - Ove
)
emory Left
#2 - Posi
s>count+1
tion Enter
Entering t
Entering n
tart;
node;
Enterting
nt+1)
-1; i++)
implemen
alloc ( siz
erflow?
t to create
ition Overl
)
red Over li
the first n
node to the
a node to
nt Doub
zeof(struc
e a node.
limits
imits. ");
node of LL
e first po
last posi
bly Link
ct node) );
");
L
osition
ition
ked List
;
ts.
28.
r
}
in
{
ptr=pt
newnod
newnod
ptr->n
count+
}
// Cond
else
{
int i;
ptr=st
for(i=
ptr=pt
newnod
newnod
(ptr->
ptr->n
count+
}
return 1;
nt DEL(int
struct
// ERRO
if(star
{
printf
return
}
// ERRO
if( pos
{
printf
return
}
// Cond
if(pos=
{
temp=s
start=
free(t
count-
}
// Cond
else if
{
for(pt
(ptr->
tr->next;
de->next=pt
de->prev=pt
next=newnod
++;
dition 4: E
;
tart;
=2; i<=pos-
tr->next;
de->next=pt
de->prev=pt
>next)->pre
next=newnod
++;
t pos)
node *temp
OR HANDLING
rt==NULL)
f("n There
n 0;
OR HANDLING
s<=0 || pos
f("n Posit
n 0;
dition 1: D
==1)
start;
=start->nex
temp);
--;
dition 2: D
f(pos==coun
tr=start; p
>prev)->nex
tr->next;
tr;
de;
Entering a
-1; i++)
tr->next;
tr;
ev=newnode
de;
p;
G #1 - Und
e are no N
G #2 - Pos
s>count )
tion Enter
Deleting N
xt;
Deleting n
nt)
ptr->next!
xt=NULL;
a node to a
e; // Note
derflow
Nodes to de
sition Over
red Over li
Node at 1st
node at las
=NULL; ptr
any other
Line.
elete. ");
rlimits
imits. ");
t position
st positio
r=ptr->nex
position
n OR Last N
on
xt);
Node in LLL.
29.
}
in
{
}
in
{
}
in
{
printf
free(p
count-
}
// Cond
else
{
int i;
ptr=st
for(i=
ptr=pt
(ptr->
(ptr->
printf
free(p
count-
}
return
nt F_Trave
if(star
{
printf
return
}
printf(
for(ptr
printf(
printf(
return
nt R_Trave
if(star
{
printf
return
}
for(ptr
printf(
for(; p
printf(
printf(
return
nt Search(
f("n Delet
ptr);
--;
dition 3; D
;
tart;
=2; i<=pos;
tr->next;
>prev)->nex
>next)->pre
f("n Delet
ptr);
--;
1;
erse()
rt==NULL)
f("n There
n 0;
("n [");
r=start; pt
(" - %d",pt
(" - ]n");
1;
erse()
rt==NULL)
f("n There
n 0;
r=start; pt
("n [");
ptr!=NULL;
(" - %d",pt
(" - ]n");
1;
(int ITEM)
ting Node
Deleting n
; i++)
xt=ptr->ne
ev=ptr->pr
ting Node
e are no e
tr!=NULL;
tr->info);
;
e are no e
tr->next!=
ptr=ptr->
tr->info);
;
with value
node at any
ext;
rev;
with value
elements in
ptr=ptr->n
elements in
=NULL; ptr=
>prev)
e = %d" ,
y other po
e = %d",pt
n this Lin
next)
n this Lin
=ptr->next
ptr->info)
osition
tr->info);
nked List."
nked List."
t);
);
");
");
30.
}
in
{
int i;
for(i=1
if(ptr-
return
return
nt main()
int ch,
int ITE
start=N
count=0
do
{
printf(
printf(
printf(
printf(
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
1,ptr=start
->info==ITE
i;
-1;
success;
EM; int pos
NULL;
0;
("n ______
("n MENU:
("nn 1. I
("n 2. Del
("n 3. For
("n 4. Rev
("n 5. Sea
("n 0. EXI
("nn Your
"%d", &ch);
(ch)
case 1:
printf(
scanf("
if(star
{
printf(
scanf("
}
success
break;
case 2:
if(star
{
printf(
scanf("
}
success
break;
case 3:
printf(
t; ptr!=NU
EM)
s=1;
__________
");
Insert a N
lete a Nod
rward Trav
verse Trav
arch for a
IT. ");
r Choice:
;
: //INSERT
("n Enter
"%d",&ITEM
rt!=NULL)
("n Enter
"%d", &pos
s=INS(ITEM
: //DELETE
rt!=NULL)
("n Enter
"%d", &pos
s=DEL(pos)
: //Forwar
("n The E
ULL; ptr=pt
___________
Node. ");
de. ");
versing the
versing the
a node. ");
");
T
r the Item
M);
r the posit
s);
M, pos);
E
r the posit
s);
;
rd Traversi
Elements: "
tr->next,i
__________
e Doubly L
e Doubly L
;
to Insert
tion: ");
tion: ");
ing
");
i++)
___________
LL. ");
LL. ");
t: ");
________ "");
32.
O
__
M
1
2
3
4
5
0
Y
E
_
M
1
2
3
4
5
0
Y
E
E
_
M
1
2
3
4
5
0
Y
E
E
OUTPUT:
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Enter the
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Enter the
Enter the
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Enter the
Enter the
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 1
Item to In
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 1
Item to In
position:
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 1
Item to In
position:
__________
ng the Dou
ng the Dou
e.
nsert: 23
__________
ng the Dou
ng the Dou
e.
nsert: 12
1
__________
ng the Dou
ng the Dou
e.
nsert: 90
3
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
__________
__________
__________
___
____
____
33.
__
M
1
2
3
4
5
0
Y
T
[
_
M
1
2
3
4
5
0
Y
T
[
_
M
1
2
3
4
5
0
Y
E
T
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
The Elemen
[ - 12 - 2
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
The Elemen
[ - 90 - 2
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Enter the
The Item i
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 3
nts:
23 - 90 - ]
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 4
nts:
23 - 12 - ]
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 5
Item to Se
is found at
__________
ng the Dou
ng the Dou
e.
]
__________
ng the Dou
ng the Dou
e.
]
__________
ng the Dou
ng the Dou
e.
earch for:
t 1 Positi
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
12
ion
__________
__________
__________
___
____
____
34.
__
M
1
2
3
4
5
0
Y
E
_
M
1
2
3
4
5
0
Y
T
[
_
M
1
2
3
4
5
0
Y
E
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Enter the
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
The Elemen
[ - 23 - 9
__________
MENU:
1. Insert
2. Delete
3. Forward
4. Reverse
5. Search
0. EXIT.
Your Choic
Exiting...
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 2
position:
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 3
nts:
90 - ]
___________
a Node.
a Node.
d Traversin
e Traversin
for a node
ce: 0
.
__________
ng the Dou
ng the Dou
e.
1
__________
ng the Dou
ng the Dou
e.
__________
ng the Dou
ng the Dou
e.
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
___________
ubly LL.
ubly LL.
__________
__________
__________
___
____
____
35.
/
a
#i
vo
{
}
in
{
// Write
and Mult
include<st
oid Matrix
int i,
for(i=
{
for(j
{
pri
}
print
}
nt main()
int n,i
int a[2
int b[2
int c[2
printf(
scanf("
printf(
for(i=0
for(j=0
scanf("
printf(
for(i=0
for(j=0
scanf("
printf(
Matrix_
printf(
Matrix_
//Addit
for(i=0
for(j=0
c[i][j]
printf(
Matrix_
//Subt
for(i=0
for(j=0
e a Prog
tiplicat
tdio.h>
x_Display(i
j;
=0; i<n; i+
j=0; j<n; j
intf(" %d",
tf("n");
i,j,k;
20][20];
20][20];
20][20];
("n Enter
"%d",&n);
("n Enter
0; i<n; i++
0; j<n; j++
"%d",&a[i][
("n Enter
0; i<n; i++
0; j<n; j++
"%d",&b[i][
("n Matrix
_Display(a,
("nn Matr
_Display(b,
tion
0; i<n; i++
0; j<n; j++
=a[i][j]+b
("nn Addi
_Display(c,
traction
0; i<n; i++
0; j<n; j++
gram to
tion ope
int a[][20
++)
j++)
,a[i][j]);
the dimen
elements
+)
+)
[j]);
elements
+)
+)
[j]);
x A: n");
,n);
rix B: n"
,n);
+)
+)
b[i][j];
ition of A
,n);
+)
+)
perform
erations
0],int n)
nsions of t
of Matrix
of Matrix
");
A and B giv
rm Addit
s on 2D
the 2 Squa
A: ");
B: ");
ves: n");
tion, Su
D Array
are matrice
ubtracti
(matrix
es: ");
ion
x)
36.
}
OU
E
E
E
M
1
3
M
4
2
A
5
5
S
-
1
M
8
2
c[i][j]
printf(
Matrix_
//Multi
for(i=0
for(j=0
{
c[i][j
for(k=
c[i][j
}
printf(
Matrix_
UTPUT:
Enter the
Enter elem
Enter elem
Matrix A:
1 2
3 4
Matrix B:
4 3
2 1
Addition o
5 5
5 5
Subtractio
-3 -1
1 3
Multiplica
8 5
20 13
=a[i][j]-b
("nn Subt
_Display(c,
iplication
0; i<n; i++
0; j<n; j++
j]=0;
=0; k<n; k+
j]+=a[i][k]
("nn Mult
_Display(c,
dimensions
ments of Ma
ments of Ma
of A and B
on of A and
ation of A
b[i][j];
traction o
,n);
+)
+)
++)
]*b[k][j];
tiplicatio
,n);
s of the 2
atrix A: 1
atrix B: 4
gives:
d B gives:
and B giv
of A and B
on of A and
2 Square ma
1 2 3 4
4 3 2 1
ves:
gives: n
d B gives:
atrices: 2
n");
n");
2
37.
/
#i
st
{
}*
vo
{
st
ne
if
pr
el
{
ne
if
{
ne
to
}
el
{
ne
to
}
}
}/
vo
{
if
pr
el
{
pr
te
to
fr
}
}
vo
{
if
pr
el
//WAP to
include <s
truct node
int
stru
*top,*temp
oid PUSH(i
truct node
ewnode = (
f(newnode=
rintf(" NO
lse
ewnode->in
f( top ==
ewnode->ne
op=newnode
lse
ewnode->ne
op=newnode
//end of
// end of
oid POP()
f(top==NUL
rintf("n
lse
rintf("n
emp=top;
op=top->ne
ree(temp);
oid DISPLA
f(top==NUL
rintf("n
lse
o implem
stdio.h>
e
info;
uct node *
p;
int item)
e *newnode;
(struct nod
==NULL)
O SPACE LEF
nfo=item;
NULL )
ext=NULL;
e;
ext=top;
e;
outer else
func
LL)
Stack Empt
Node with
ext;
;
AY()
LL)
Stack is e
ment Sta
next;
;
de *) mall
FT ");
e
ty. n");
Info=%d i
empty. ");
acks usi
loc ( sizeo
is deleted.
ing Lin
of(struct
. n", top
nked Lis
node) );
p->info);
sts.
38.
{
te
pr
wh
{
pr
te
}
pr
}/
}
in
{
emp=top;
rintf("n"
hile(temp!
rintf("n
emp=temp->
rintf("n"
//end of e
nt main()
int ite
top=NUL
while(ch
{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
PUSH(it
break;
case 2:
POP();
break;
case 3:
DISPLAY
break;
case 4:
printf(
break;
default
}
}; //en
return
");
=NULL)
|%d| ", te
>next;
");
else
em,ch=1;
LL;
h!=4)
("n MENU:
("n 1. Ins
("n 2. Del
("n 3. Dis
("n 4. EXI
"%d",&ch);
(ch)
: //INSERT
("n ENTER
"%d", &item
tem);
: //DELETE
: //DISPLAY
Y();
:
("n Exitin
t: printf("
nd of while
0; }
emp->info)
");
sert a nod
lete a nod
splay Stac
IT n Your
ITEM: ");
m);
Y
ng.. ");
" INVALID
e loop
;
de. ");
de. ");
ck. ");
r Choice: "
CHOICE. ")
");
);
39.
OU
ME
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
|
|
|
M
1
2
3
4
Y
N
UTPUT:
ENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
|90|
|89|
|64|
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
Node with
a node.
a node.
y Stack.
ce: 1
M: 64
a node.
a node.
y Stack.
ce: 1
M: 89
a node.
a node.
y Stack.
ce: 1
M: 90
a node.
a node.
y Stack.
ce: 3
a node.
a node.
y Stack.
ce: 2
Info=90 iss deleted.
41.
/
#i
st
{
}*
vo
{
st
ne
if
pr
el
{
ne
ne
if
{
st
re
}
el
{
re
re
}
}
}/
vo
{
if
pr
el
{
pr
te
st
fr
}
}
// WAP t
include<st
truct node
int
stru
*start, *r
oid INS(in
truct node
ewnode = (
f(newnode=
rintf(" NO
lse
ewnode->in
ewnode->ne
f( start =
tart=newno
ear=newnod
lse // INS
ear->next
ear=rear->
//end of
// end of
oid DEL()
f(start==N
rintf("n
lse
rintf("n
emp=start;
tart=start
ree(temp);
to imple
tdio.h>
e
info;
uct node *
rear, *temp
nt item)
e *newnode;
(struct nod
==NULL)
O SPACE LEF
nfo=item;
ext=NULL;
== NULL )
ode;
de;
S at END
= newnode;
>next;
outer if
func
NULL)
No item to
Node with
;
t->next;
;
ement Qu
next;
p;
;
de *) mall
FT ");
;
o delete.
Info = %d
ueues us
loc ( sizeo
Queue is e
d is Delete
sing Li
of(struct
empty. n"
ed. n", s
inked Li
node) );
");
start->info
ists.
o );
42.
vo
{
if
pr
el
{
te
pr
wh
{
pr
te
}
pr
}/
}
in
{
oid DISPLA
f(start==N
rintf("n
lse
emp=start;
rintf("n
hile(temp!
rintf(" -
emp=temp->
rintf(" -
//end of e
nt main()
int ite
start=r
while(ch
{
printf(
printf(
printf(
printf(
printf(
scanf("
switch(
{
case 1:
printf(
scanf("
INS(ite
break;
case 2:
DEL();
break;
case 3:
DISPLAY
break;
case 4:
printf(
break;
default
}
}; //e
return
AY()
NULL)
Queue is e
;
|");
=NULL)
|%d|", tem
>next;
| n");
else
em,ch=1;
rear=NULL;
h!=4)
("n MENU:
(" 1. Inser
("n 2. Del
("n 3. Dis
("n 4. EXI
"%d",&ch);
(ch)
: //INSERT
("n ENTER
"%d", &item
em);
: //DELETE
: //DISPLAY
Y();
:
("n Exitin
t: printf("
end of whil
n 0; }
empty. No
mp->info);
n");
rt a node.
lete a nod
splay Queu
IT n Your
ITEM: ");
m);
Y
ng.. ");
" INVALID
le loop
Nodes. ");
");
de. ");
ue. ");
r Choice: "
CHOICE. ")
;
");
);
43.
OU
ME
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
E
M
1
2
3
4
Y
|
M
1
2
3
4
Y
N
M
1
2
3
4
Y
|
UTPUT:
ENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
ENTER ITEM
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
| - |64| -
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
Node with
MENU:
1. Insert
2. Delete
3. Display
4. EXIT
Your Choic
| - |89| -
a node.
a node.
y Queue.
ce: 1
M: 64
a node.
a node.
y Queue.
ce: 1
M: 89
a node.
a node.
y Queue.
ce: 1
M: 90
a node.
a node.
y Queue.
ce: 3
- |89| - |9
a node.
a node.
y Queue.
ce: 2
Info = 64
a node.
a node.
y Queue.
ce: 3
- |90| - |
90| - |
is Deleteed.