0% found this document useful (0 votes)
15 views10 pages

Stacks Using Arrays by Tanishq

The document discusses stacks and stack operations using arrays. It explains the LIFO principle of stacks and demonstrates push and pop operations on a stack. Sample code is provided to implement stack functions like push, pop and display using arrays in C language.

Uploaded by

Science lab
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)
15 views10 pages

Stacks Using Arrays by Tanishq

The document discusses stacks and stack operations using arrays. It explains the LIFO principle of stacks and demonstrates push and pop operations on a stack. Sample code is provided to implement stack functions like push, pop and display using arrays in C language.

Uploaded by

Science lab
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

HKA

Dr. L BULLAYYACOLLEGE OF ENGINEERING

STACk
|stacks dynamie data staututes thi: Iloo the
last. a Rust ot/Ltfo Th at ten
|to a stack is R, Aust one to to be fneted
be deletel from!
stazks have ve stidons on the inseskoa and
f elemets slemetes Can be deleton
foorn one end ef
iasested os deleted onl,
the staek ie top
stack Cuample
staek size:
eshb 2

,2,! 6

Pop2
Dr. L BULLAYYA COLLEGE OF ENGINEERING

STAck Dsivg ARAAYS


|stacks ae dnaníe data stutee that folb te
tast in kt out (LIfo) paiefple The last
betnseted to Hento
a stact a he fit one to be

bu Ekample, ou hae a
stack of trays table.
"The tay at he top f the stact is the fust item to
be move d you tequée a fay faom that stack
Ihesfrg and dele kra elanete
tek have bestuetons
stacks oa the fertan and
deleton f elements.elemets an be fasested ox
deleted an le one end of thostak ie fim
top
Dr. L BULLAYYA COLLEGE OF ENGINEERING
AM

inchally stact isemphy


top: -l

) Rshlstact,s,)

sbp elemet tp:o


)Rach lstak,o,a)
lo
5

) Resh(staek, zu,)
224

)AS top:2, Cusent síse f stack is topet,ie 3 Nos


stack is tull ,as 3 is maulmum siçe of staek.
Rushlstactn)
AS,
OVERFLou cONDITTON!
Dr. L BULLAYYACOLLEGE OF ENGINEERING

tos stacks csirg ay


#inc ude stole.hz
#
#cludez lono.ho
de he SIZE 5
void Push0:
Void Pop ;
Noid diploy ;
it stack.oves flos);
it sta ck. vnder flow0:
int top -l;
Void Pushe
int data;
if(stack.over flowl). )
Pptf /"stack overflaw ");
else

tf"enter data t purh;


Slant ("old" adata;
Dr. L BULLAYYACOLLEGE OF ENGINEERING

op++;
ssay [to p]:data;
Rid(he data you
2
wou estescd:dl"data:
void popl)
(stack, vader floul )
Pte staek nder flooa
else

top.-;

Vofd displayl
iat
1£(sfackvndes flos (): - )
AMAPA Dr. L BULLAYYACOLLEGE OF ENGINEERING

-lse
eslis top;i;-)

ft t staek. oveg flow )

(top: s)

3
else

2
Ft stackendey flow)

xetern 1;
Dr. L BULLAYYA COLLEGEOF ENGINEERING

else

itch
cha t:
STACk opERATLTONs. ...n):
Ratf"n push-s rn pop->2) npúplay-g)a);
do

Ptf "hetes yeus chote:n);


Stanfl"ld ch):
Ssltehlch)
(ase I:
Push (;
bieak;
Popl);
b»eak:
MAAAuB
AMR Dr. L BULLAYYA COLLEGE OF ENGINEERING

Case 3.
displa, C);
bscak;
detautt:
3:

tgetch ();
wtee t:'y'llt:');
getek0):
Dr. L BULLAYYA COLLEGE OF ENGINEERING

Pop -> 2
daplay-z3
cholle
yeut
ttes data to peash:1
xtes
Stey dota you entesed:22
do twant to Conkne?
entes yout chohoi ce:t
Entes data to pesth::3
ter data you erteed:31
do cwant to onthue?4
enter your
entes cheice:!
data to push;e e
extes data you eteed
Pued:u4
you want to onthue?y
Dr. L BULLAYYA COLLEGE OF ENGINEERING
.

ente yo cholte:t
entey data you psh:55
entes data etered:ss
you
Do you coant to contne? y
entex your chote :2
Popped item is : 55
kont to Conhue? y
entes yous choice :3
33
2 2

do

You might also like