stacks and queue

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Date.

Expt.
No. 01.... Page No..2.....

1.a Stack using Arxay


incade <stcío.h>
tinctude<stclub.h>
NOtd push t) pop,displa)i
define MAX 3

i0t top-L stack CMIAX]

while Ct)
paiotf(lnStack Menu--n
pint!("4. Pushin ");
pxiot! 2.Pop.ln)2
pxint! (u3.Displau to")2
prinr "
4.Exrt.An );
pont{(" Eotex your choíce:")
S can!"od" & choice :");
Switch (choice )

Pprsint{(" Stack overftow")i

push C) barak;
case 2: if (empty ())
pain (
Stack Underlow"):

popc), baak;
-AchievER
Date.

No. 1Page No. R...


Expt.

case 3idispla C02


brak
case 4 exit(o)
bocak
cetault i print{("Tavalid optton. ";
Noid pushc)
R if(top <MAX)

iot num;
poiotfC Enttx on inttqtr to be pushed: ");
S Canfuf.d&oum)
toptt,
stack Ctop] num;

lse
pint{lnStack Full.\o ")2
display0;

Noid pop)
1f (P top z=0)
is iY.d, stack Ctop)i
pxint f("Item popped
top-

-AchievER
Date..tes

Page NNo.
No,
Expt.

else
printí ("n tack Empy.\n")2

display);
io+ fulO
if(top MAX)

else

|iot empty)
1fCtop=-)

void displa )
iot head-top
if Cheadz=0)

poini{ The Rtems in the stack cn:")2

-AchievER
Date..semm

No,
Page No. .
Expt.

while C head1 )
piotf\nd" stackCh tad 1)2
bead--2

else

pxínff(\n Stack emptyn

-AchievER
Output
-111Stack Menu
4. Push
2-Pop
3- top
Disploy
4.Exit
Enttr our choice : 1
Enttr an inteqe to be pu shed:16
The ittms io he stack at. C14)
16 Push
top
--Stack Menu stack
4- Push

3.Display Push(24)
4.Extt top

Ente your Choice: 4


Enter anintqer to pushtd;24 stack
The ems in the Stact are
4

Cia)
Push
Stack Menu-
1-Push top
9. Pop 4

4
3. Diaploy
Ex i4
Stack
Enter yourchoice :1
Enttr an intger tobe pushed: 17
17

24
----Stack Menu
4.Push push
a- Pop
3 Disploy R4
4-Ex?4
Enttr your choice: 1.

Stack Overflow. stack Ovufto)

-Stack Menu
1.Push Display
.Pop
3.Disploy
top
4 Exi4
€nter your choíce :3
The ?tms in the gtack are; Stact

24

Stact Menu >Pop


A. Push
(1a)
a.Pop
3- Disploy
4Extt
Enttr your choice'2
Stack

The items in the stack are:


Q4
16
-Stack Menu--
1.Push

33- Pop(4)
Display
4.Exit
Entey your choice: Stack
Hmpopped 240 i

Tht ttms in the stoack are:

-Stack Menu
4. Push
Q- Pop
Pop(1a)
3.Displa y
4.€x?
Entr uour chotce
Item popptd.16
Stack (s enpty.

Stack Men u

4.Push
2.Pop
3.Disploy
4.Exi+
eottr uour choice :
Sack Undertow Stack Underflow

Stack Menu
A. Push
Q.Pop
3.Drsplay
4.Exi

Enttr your choic i4


Date 14lc2024.

Expt. No,4,b Page No, 5

.bQueLIL usíoq aro4


include <tlio. h
tinctude< stdib.h
4 define sIZE 3

void insea ar (iot tem, i0tgC], iot *


void fxont
delete (int qC1, iot iot Y
Noid display Cint ql1, iotf, ot )
int qfutl (iot ):
int qmpt Ciot f. iot )2

iot ch0ice, ittm, f=0,YealsIZE


foxC::{
print!C\t \E Queu aperatían \oln
print£cs.pushina.Papln 3. Displala Exrd \n");
print"\EiE
Scanf

Case
Ctd,&chaice)
Switchcchoic
1 printf
)
Entt yOur choice i "

("EotYthe itemto be insertc )


scanfc"d", &item)2
inseot tox (item,q,&n2
btak:
case

bxcak

display(9, f):
brcak;
-AchievER
Date...

Expt. No. Page No.

Case 4 exi(o)
deiauldiiot f(^ ToNalid Laput ry Ag ain\o);

void ioseat xax (tot item,intal1, iot Y)3


painifl\E\E Gueue ovenlowln")
tugn
alt+(*)Eitem;

void delete front(int aCJ, iot xf, int*y)

pxintf(E\E Queui daderflow\o")

poíott Cu Pop Succesrfalelement delettd Ldn


qlcx)44]);
xf=0

xoid display Ciot ql intl int )£


if(qempty Cf, ))4
printf(Queue is emptyn

-AchieveR
Date.

Page No.
Expt. No.

pint{ ("\t \E\t Queu Cooteo ts \nln)


fox (int f=f; iK= i+4)

int qcmaþt (int f int )F

-AchieveR
GvdOutput
Quue Opevation
4. Push
Aontrar
Q. Pop
3.Display
4.Ext 4 ushcss)
Enttr
En tr
your cho ice
em to be
h
1insd5S Quiu

Queue Opratton (rontTaT


4. Push
.
. pop
3. Push(2
4) Gueut
Display
4.Cxit
Crttr uour choice:1
En-tr the 4em to be
insetd; a9
Quue Operotion Gueue
4. Push
d-Pop
3. Display
65a 36
Pus h (s4)

4€xi4
Cnttr your choice 1
tnttr the itt m to be inse fed:3G

Quue operation QuLue


1.Push Push
bo

a.Pop 55 X
3. Drsplay
4exit
Enttr your choice 1
Enter the itemn to be Oveftow
insted; |2 Queu
ueue Overftow
Queue pevation
1. Push
a. Pop
|3. Display
4.Ext 55
Entr ourchoice
u

Queut Contots
:3 front
TLOY
|56| Dtsplay
|a9|
|36|
Quue Opration
1-Push 2
aPop 36
3-Disp lay
4-€xi4 Pop(55)
Popl6s) ent reov
Enrter your choia :)
Pop Succusful,element deletedi gss

Gueue Opration
4.Push
&.Pop
3.Drsplay
4. ExP4
Pop (ta)
Enttr uour choice ,a
Pop Successful,eleenent deleted aq
Queue Operation
4. Push Queu
a.Pop
3.
Display
4- Exit topt8s)Empty
enttr your chotce a deleted 36
Pop Suceess ful ,element

Gueue Operaion
1.Push
Q.Pop
3-Display
4-Exi4
Pop X,Qud empty
Cottr your chotce &
Stack Underftouw
Queue Undefow.

G ueue Opevation
1.Push

a.Pop
3.Dísplay
4. Exit
En ter your choie: 4

You might also like