0% found this document useful (0 votes)
9 views

Queue in Linked List

The document contains code for implementing a queue data structure using linked lists in C. It includes functions for inserting elements, deleting elements, and displaying the elements of the queue. The main function provides a menu for testing these functions.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Queue in Linked List

The document contains code for implementing a queue data structure using linked lists in C. It includes functions for inserting elements, deleting elements, and displaying the elements of the queue. The main function provides a menu for testing these functions.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#i

ncl
ude<st
dio.
h>

#i
ncl
ude<st
dli
b.h>

st
ructnode

i
ntdat
a;

st
ructnode*
next
;

}
;

st
ructnode*
front
;

st
ructnode*
rear
;

voi
dinser
t()
;

voi
ddel
ete(
);

voi
ddi
spl
ay(
);

voi
dmai
n()

i
ntchoi
ce;

whi
l
e(choi
ce!
=4)

pr
int
f("
\n*
***
***
***
***
***
***
***
***
Mai
nMenu*
***
***
***
***
***
***
***
***
***
*\n"
);

pr
int
f("
\n====================================================
=============\n")
;

pr
int
f("
\n1.
i
nsertanel
ement
\n2.
Del
eteanel
ement
\n3.
Displ
ayt
he
queue\n4.
Exit
\n")
;

pr
int
f("
\nEnt
eryourchoi
ce?"
);

scanf
("%d"
,&choi
ce)
;
swi
tch(
choi
ce)

case1
:

i
nser
t()
;

br
eak;

case2:

del
ete(
);

br
eak;

case3:

di
spl
ay(
);

br
eak;

case4:

exi
t(
0);

br
eak;

def
aul
t:

pr
int
f("
\nEnt
erval
i
dchoi
ce??\
n")
;

voi
dinser
t()

st
ructnode*
ptr
;

i
nti
tem;
pt
r=(
str
uctnode*
)mal
l
oc(
siz
eof
(st
ructnode)
);

i
f(
ptr==NULL)

pr
int
f("
\nOVERFLOW\
n")
;

r
etur
n;

el
se

pr
int
f("
\nEnt
erval
ue?\
n")
;

scanf
("%d"
,&i
tem)
;

pt
r->dat
a=i
tem;

i
f(
front==NULL)

f
ront=pt
r;

r
ear=pt
r;

f
ront-
>next=NULL;

r
ear-
>next=NULL;

el
se

r
ear-
>next=pt
r;

r
ear=pt
r;

r
ear
->next=NULL;

}
}

voi
ddel
ete(
)

st
ructnode*
ptr
;

i
f(
front==NULL)

pr
int
f("
\nUNDERFLOW\
n")
;

r
etur
n;

el
se

pt
r=f
ront
;

f
ront=f
ront-
>next
;

f
ree(
ptr
);

voi
ddi
spl
ay(
)

st
ructnode*
ptr
;

pt
r=f
ront
;

i
f(
front==NULL)

pr
int
f("
\nEmpt
yqueue\
n")
;
}

el
se

{ pr
int
f("
\npr
int
ingval
ues.
.
..
.\
n")
;

whi
l
e(pt
r!=NULL)

pr
int
f("
\n%d\
n",
ptr-
>dat
a);

pt
r=pt
r->next
;

You might also like