To write a
Pghon poam tts áolue
Yn Valua dounte dtinationand
aualayvalue.
Btt the bae lonaitio chek t n
duttnaion and outunit.
Sp 3 Again Snslde de duntion cal!
Cal e
Juntion uith Hpo,ameten usth
Chang cthe aoameto n-l-, Sounle
auaiary aud deginatin:
and
Sp pount the aten ade n
lowne do destiration
9oe tke cau tiu funtlion
Cuth Chanq the paamety Ih-!
auedlany olettnation, Spune
Gret the Thput n value yom nen
and Cl e unttion
duy touon s4hano (n, &owne
at)
touue of - hanot (n-!Soune, autliay
h= tt (tngut (' Etn then ale:'))
tousn -o- hanoi (n,Ma",'Be)
Rerut
Thus dthe pivoam to
(was celeuted eluawy
Basic cpeationon Srga Lnedliit
doletion, oonch, Trauere diglay and
(Dunting te haole.
aigotthm
Stopl TN tiaizQ a Nked dit clas tuf th the
uthods pr Inawt, dolote Adcth cplay
Oval Couting hooles
tp &|- nplement the Woole cles to onoate
hddual noles wuith clata and oujpunce
co sthu nesct noole
Sap 3} TniÀalze. dhe Pnko it clas with a
head þoirtin Alt o None.
stp H- 0mplement metuody t 9niet a nooe
at bag?ning enod ertedpesd posttuon
|Stap 5 p l u t mithods cto dalete a node at
hoglning nd and at dre<isd postlon
|Szpbl- mplemnct o method o doos oro ghan
olata vale tn sthe nked Lit
|Spt Zmplement a methe to osplay tte
loment ythe nte llt and cout
no dy
byt input rom the and oesb.
Cles Node
da< 9nit- (ael jdati)
&sloata dota
ell. heaos one
Cwrsent = lhead
uhile Cwentt
þoünt (unsert oata j end wy
Cuet Cent
= nAt
pownt )
dey ruent at- kegln (sely, date)
hous noole oolo (oaa)
neu hoole, net
dell. heod
new hoole
cay ?het- dt- pos? Hon (del, data [poatiod:
hew ole Ubole (doTa)
forin vangL (potion -):
powt Ctnwalld podtion)
Cuont cwnnt. est
new holo not nent.nnt
Cusent. net =h hoole
duy fnertot and (al jdaa):
rew hoceoe (aata)
. hend uw-hola
e
uile Coont. net
de oelet
pount (" it u emptyy Gannot
delst.')
che. hood dehond- het
not
pount (1'it bampty, Cannot dalete ")
Sy not de. hoa. nett
Bll. had Wone
Getn
Cwrent de. heap!
tuh? le Cwnent. het.hestt!
ueen lwent next
Cuent. net = Wohe
delet-at- postton (deti postion):
A!. heocl delf.heod.neat
Oetwn
Cuonent dell, hos
Y cent s None or Cuvt. neat s Wone
pount ("2nualid pottion)
Cnent w t . hesct
Cwrenthets Coret. ntnat
dej a h (aely dats):
pOSHon =0
whle usrent
1 cotdata = data
þaüs"Eumct Tdaty yourdaet ytion
Cnent =loet. het
pouint (puEmert toatay not ound tn it )
det Cout o (del):
Cusen dll.heal
unile Cuent
Cut=ctneset
point (No eL Nodes' )
uhile thel
pount ("1. Tmot ot Bequhg
pount(2.det at und )
pouunt (3.Tnet at þoson ")
pount (". Dolet at
pount (M6. Deltt at end)
þoint "4. Delatt at posttion ")
pout (a,Leanch )
þount "9. Count o Mode)
Chot ce =Int (hpt (" Enten youn chot )
data Tnt (?hput ("Enton oota to înnt at
The
lEkeslit. Iuent atkeatn (oat)
data = Tnct (Input (" Entoi data to Bnaet atth
lhdl;))
Jlinda it.teent-dt edldaa)
cata n(tnpuc ( Ent dada to Irust; ))
posT toon a tnt (npt' to postbon to Jhwt:")
intel lit.tuet at- poton (dat, posltion)
nkacl t . delet-at kagin ()
al choca
Jnkeol dito olalote dt-end )
posPlon = vt-(nput ('nta pogition to dlelat )
eol it. oelcdt poatuon Cpedtion)
data = rd(?npct l'nto, data to daart;))
Unko diit . erh Cdatau)
Jinteollit. dlspkhy )
linkesl lit. lountB)
Di chofe ==lo!
boeak
pount ('waltd cheie")
Result
-Thus the tython osram to
1mplaneat the baste Lhked lit bpealion
was pformed Jormad ucnhully.
Baste ereNaon onsta k
An
To wit a Pgtuon joopam cto tnplamend
the &tack baste onoratons ke pushy fopt
olgortthmy
Coacto a clas called dtak and dafne
a Init dunction wtth ftms as e
data memken
Creati a yncton puk add th tu
getting tnpu cto Pnu vetabe
Deyine oa fun ction fop yurit Check
Btack ço chpty ele Ceeate a new
it atore talk element Cud slp
the lat elennt then edtoret e
hew t to Ttom it.
Pene a pook yuncton det the
dast elemant yom the 1ns asry
te hegattue Thde -1 and
uig
etwn it
Pnaly dafins a dsplay and
þount the al vale tn tee Stack
pouit
ffnetanal
8ap b!
butting inpt om
ane jenfonm omeatiors.
phogram
clas stak
dodf. ttams.appund (ttni)
pount ("3tok is emty anno pop
qhom anemptg Stae")
pouins ("Statk àempty. Cannot aek
om an enpty stacu i)
odej dsploy ldel)e
pount ( dey.Ttiu)
dtae - Stak )
tuhilte
chote e rt (rnput ("Ento you clo?a :n))
Stem - Tnput (nto the tem to
puh?
po ypadtm= dkack. popt)
t popped itum us Not None
top-1tem= dtatk. pek )
peit (TopTtzm + top-tm)
Atek. dUsplay )
oeak
Ret
Thus the ython onnam cto
?mplemet baste Atack oneeion uas
Qxecuted sueally.