0 ratings0% found this document useful (0 votes) 78 views11 pagesImplementation of Stack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Data Stuctare Useug Cc
Unit-2 ,
alee
Stack + (Won Pemrtve Limeay Dada Stoucttre)
A stack 18 om ordlesedl grouh Ciist) oP homogeneous
elements Adlon of nets element amd Deletion of
excigtme element are clone fem only one evrd called
“Tob of the stack. ‘The rem last abled will be the Pirst to
be removed. Prom the dace. A stack t¢ alto called
82.5 Plater placeol on the counter oP oafeterca
7 Disks on a feg.
— Books on a table. one over other
= A stock of neatly Ploleal shits.
Basic Ons on Stack *
© Pash * the recess of adoling mero element to the
dep of etack is alle Push operetion.
@ Po: the preceas, of oleletiny aun element Prem top oF
the stack ts called Pob operation
Overfless 2 UnolerPlows 1m Stack ! —
Tha (8 the Setuatim when the stack
becomes full and ne mame elements aan be busheal on
Yo the stack. AL thir pomt the Yb 6 brent ot the
highest beaten of Stack,= ees tohen the-etace eign no
element anol yeu wwomt to perfiom a Ab ebesatian,
@ wmdlrpleco ects. The teb is bresent af some nan valid
pasetion , xebresentiny the embty stack,
“eb this refers ta the to oP the etace JL ts tuted to
Check. the everPlos amd dmderPloo. Initially tobsfaie-|
(ManKsIZe te use thin term to vefer to the ‘mascrmum
Size OP the stack. In array tmblementation oP
stack, mAxeize vefre Yo ize of arey .
Arey Smblementesion of Stace
Here the stack 19 sepreser neal
treush om areap. Ome u9ay to Implement otack 1g fo.
have awpdbla stoucture there a
vastable called tob tc
cred to keeb the location of elements im the Hack,
B4 }
A Stace toith Selemende A Pell efrawe a 2
dofe= 4 do-=Maysize- } BSPosh operation fi
Algeot thm
~Plith steak, stze , dep, lem)
Sack (¢ meas array of Sze SIZE
bop ts top of the stack.
Hem 12 value to be aadloleal.
{. Coheck overPloc)
uf (deb== s1ze-|)
bemt over Plow and eset
A deb= ep!
8 Stace [4eb] = er
4. Step
C- Implementation,
Vow push (mt a)
[ “ap Gleb == crnysize-))
| [* gomatpceverties),.
| " coxit (6)
ele ;
; dep = feb +1,-
| Stackedob T= Hey,
fe es me
2Bb_eperadion :
Algeerttim
Bb Cotocte, eb, fem)
kb Li: Cohece Onolerfleio)
9 Lkb==
© pad Cy Onde.
3 te),
2 5
Gleb 21 udem= atack eb)
Seb 8° fop= te —/
skp Stop
ect Orla of ae
werol dshlayC)-
g mt uy.
AP (seb==-1)
mt? (elacke :
a PC ck 1s empty”),
© Parl d= -. ae
3
La
gs
wool Rb Cet
a
t
Sint tem ,.
up (iep=="0)
pond a OmalenP ios) $
a
e
a
spomie” Hern bespeal =
‘ tol’ wtem
i
evcit Ce), .
i
Heme pele,
no
e
@
ay
),.C Bossom te tmblement stack. Using Array
= (neludle < stole, h>
at Imeludle £ covue.hy
He defne marsize fp
mt “deb = ly
int stacteEmaxcize],,
Wet push (mb a)
iE
Co 9P Cdepa= magize-()
bom “stack Overflow ,
else ;
rey,
Stoek Cob] = a.
3
mt bb)
58
[ Int demmp,.
Kiko
J bom “tack amolereles)
| elke.
| i; deorp= stack teh),
a
| - 3
| detum Citemp)), FVet olisblayl
e (md dy
dt Cep== -1)
anc Cahe ently,
as
BtEC \n The contends of atace aoe),
Per (= debs L7 = t-—)
prt] Cn \t tol’, stack),
z
ai
\sel main)
2
@ mt J, ch, data,
5s
do
E pent (min).
buts C1. Path),
‘pede (2. RpY),»
bude ("S-cluplay"),,
Ads ("4 exit),
— sbeets (“onder Your choice ; D;,
soomp "fol \ seh ),,
sisttzh (eh)
core | }uote (“enter element Hou
seomP C” fuol'y dada),
bush (olata),,
alublay C),,
break,.
ane 3!
loom do push”),
Hest Rta element = fa!’ bob’)
obsplay C),,
break,
absplay C),0
E Eye
exert (2),.
default :
Ce :
ae 4s
brent PC" tea hatte emberedl easong chatce
2 [/ enol of sertel,
3 while C1)» (eesl ef alo loop
-goteh(,
3 fl enol of mom,Latte! hist mblementation of eface —>
Another way to umblement etace com be corth the
helb of limveol fist, while implementing bertseol Lied —tr
Stack Laing limxeol list Wwe need 46 make cure tay:
basic pespertrer of stack «¢ met Varlated s.e Imsertim
amd odleletm do be done at ave. end only,
As the imsestton 2 deletion com be oloro ar- the.
beginming or at the enol oP a dmeed list, be con
Implement ack Using amy oP the too. But te iP. le,
inseat [olelote. at the beginning ef dnted let, the time
complescit, till be OC) as @mbaredl fo the @4 then
Wwe perfrrm Imserten (deletion at the endl. S im
6% oaliscreston use cotl! implement tach Using tmkeol
list omel peofarm (rsertion and deletion at the
begimme,
C_tmblementakin af atace’ Gary level hast
#imaltole
& moludex amie. hy :
stouct efacw Ge define tock */
(md (nfs ,.
Sect stool. ¥next:,
3 ¥teb = Noy fevere push Cimt Her?)
f: ghuct ack *S,, oe
S= (shuct stack #) enallee (exces),
4(2>
| & g_y1nfo =tHem,.
| Sp next = toby.
4 HES
ele :
putsC “om net crease nets reole"),
getehC) ,»
eS cxit(e)e de,
- es A cP ;
umt te
Cie aa
2 pads” undesple™),.
| ae Sc i!
ele
| ® stouct efack pte 50
bO= dob,
Heme fop-7 (Nf 50
uep=, top—y next,
Foee(sbtr Dy
| a, etm Giem), .
eSVewl olusblay (>
tomb = top y
[ E stout Stack xemby,
|
|
bante (ln The efack nae ¢ ww),
chomp C7 deh),
| tohile Ctemb >
| l" bunt C—-y 1-01", demb->mfe,»
4 tomb= temb—rneoct,,
at
dont (7 -ynuit\n"),
a nagye
oi
int ttem, ch, x, dada, choice ,,
do
2 pede (Ws Aach”),,
pads 2. Fab"),
eds (iin eed
“bude (“lon enter pour choice),
sonP-C' td", 2ch),,
_ Stoiteh Ch)
é
coxa:
ont? Cn ender oadoe be hushed), ul
scoomb-C “fol, 2dlada),,
push Tet
dupley La
breakpwroub Jo jaa)) 5
C4098
2yo-—p f pe]? “CHM C
‘Ppine Jo pal) ¢
“Ce) piova
* 3 or
°eoeg
“CO Roygono
{oPays 4a fd) Prousye ou. uy,,7 jrwesh
(oR 1 7 a6
xO P/ = puowrje poddy wy, Daweh
Cl- =] 6) ab
“dep ve
56 WO