0% found this document useful (0 votes)
5 views5 pages

Sandipan Das Notes

Uploaded by

Sandipan Das
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)
5 views5 pages

Sandipan Das Notes

Uploaded by

Sandipan Das
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

1.

Write a function to Bmn plamewt infi to rafia of


esþreiom.
def Pre cedence Cop):
i op in (+,-):
return 1
op in ( y):
Yeturn 2
if op in ('):
Yeturn
return 0
def is-operator (c):
return c in {+', -, *, ,
def infin-to-Prefi: (ezþression) :
def infito- Postfix (exp):
Stack C]
Yesult I
for char in exp?
1f char. isatnum (
Yesult. apbend (char)
elif char s=
Stack, aþpen d (char)
elif cars ':
while Stacu and Stacu-13
Yesut.abþend (stak top(O)
Stack. pop )
else

Whiu stack ano þreeedente (Staeu I] S Frecedente


lehar):
reswt abþend (stau. pop)
Stau tand (ehan)

reswt ao þend (Stan. poPO)


Yeturn ' , join (re sult)
expession : J]
. jein('('if ce')' else') if Cze t'else c for in
erpmien)

ezpr ="(A-ole )* (A/k-L)"


Print (" frafra exfsioni , tnf too frefir (ezþr))

Output:

prefa ¢pressin!
2. Nrite a uncin to chek th ( ' o
e» preion .
def
is- balance d (exþresiom):

for char in eaprasiom


ez þrein
i char in
Stacu, a þand (cha)
eif c han in

stauu. pop ()! pais [cha]:


Yetum FalSR
Yeturn len (Stau) =0

expr2= "A]* (e-b)?"

print ( is bal an ced (enpr1) )


print (is balanced (eapr))
print is-balamed (enprs))
nt is-balanced (emr))
Outþut!

Tru e
Fayse
Falte
3. ite a uncitu to imtlement a
daa sructu t teuse
ress.
Class MemonyAllo tatr:
defintt-- (Sely, Siae):
Self
[(o, si2c)]
def alotte (Self,
Si2):
for i, (strt blok Si|) in enu wate (Sf. Brulist):

alertated Stat Stant


Self. sre.bst. poPi)

Yeturn alratd Start


Taise Memsny Errnr " No sufuent anailal,)
def re (self, Stonty iee)

elße
merged Wt. aobd (tfrav- Start, prw i2<))

all reator e Memanyreoatr (ro)

|bhy 2 lstabor. aotate (20)


Prin 4"tsaed biree at indez 41reu 24')

blecx 3 allstatr. allrtute l5)

AmdeaO

You might also like