SlideShare a Scribd company logo
def isEmpty(S):
if len(S)==0:
return True
else:
return False
def Push(S,item):
S.append(item)
top=len(S)-1
def Pop(S):
if isEmpty(S):
return "Underflow"
else:
val = S.pop()
if len(S)==0:
top=None
else:
top=len(S)-1
return val
'''def Peek(S):
if isEmpty(S):
return "Underflow"
else:
top=len(S)-1
return S[top]'''
def Show(S):
if isEmpty(S):
print("Sorry No items in Stack ")
else:
print(S)
'''
t = len(S)-1
print("(Top)",end=' ')
while(t>=0):
print(S[t],"<==",end=' ')
t-=1
'''
print()
# main begins here
S=[] #Stack
top=None
while True:
print("**** STACK DEMONSTRATION ******")
print("1. PUSH ")
print("2. POP")
# print("3. PEEK")
print("4. SHOW STACK ")
print("0. EXIT")
ch = int(input("Enter your choice :"))
if ch==1:
val = int(input("Enter Item to Push :"))
Push(S,val)
elif ch==2:
val = Pop(S)
if val=="Underflow":
print("Stack is Empty")
else:
print(val)
'''
elif ch==3:
print("nDeleted Item was :",val)
val = Peek(S)
if val=="Underflow":
print("Stack Empty")
else:
print(val)
'''
elif ch==4:
print("Top Item :",val)
Show(S)
elif ch==0:
print("Bye")
break

More Related Content

DOCX
Database Query Using SQL_ip.docx
VandanaGoyal21
 
PDF
sql_data.pdf
VandanaGoyal21
 
DOCX
sample project-binary file.docx
VandanaGoyal21
 
DOCX
Computer Networks.docx
VandanaGoyal21
 
DOCX
Computer Networks.docx
VandanaGoyal21
 
DOCX
functions.docx
VandanaGoyal21
 
DOCX
Functions.docx
VandanaGoyal21
 
PDF
CLASS 10 IT PRACTICAL FILE.pdf
VandanaGoyal21
 
Database Query Using SQL_ip.docx
VandanaGoyal21
 
sql_data.pdf
VandanaGoyal21
 
sample project-binary file.docx
VandanaGoyal21
 
Computer Networks.docx
VandanaGoyal21
 
Computer Networks.docx
VandanaGoyal21
 
functions.docx
VandanaGoyal21
 
Functions.docx
VandanaGoyal21
 
CLASS 10 IT PRACTICAL FILE.pdf
VandanaGoyal21
 

Recently uploaded (20)

PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Ad
Ad

STACK.docx

  • 1. def isEmpty(S): if len(S)==0: return True else: return False def Push(S,item): S.append(item) top=len(S)-1 def Pop(S): if isEmpty(S): return "Underflow" else: val = S.pop() if len(S)==0: top=None else: top=len(S)-1 return val '''def Peek(S): if isEmpty(S): return "Underflow" else: top=len(S)-1 return S[top]''' def Show(S): if isEmpty(S):
  • 2. print("Sorry No items in Stack ") else: print(S) ''' t = len(S)-1 print("(Top)",end=' ') while(t>=0): print(S[t],"<==",end=' ') t-=1 ''' print() # main begins here S=[] #Stack top=None while True: print("**** STACK DEMONSTRATION ******") print("1. PUSH ") print("2. POP") # print("3. PEEK") print("4. SHOW STACK ") print("0. EXIT") ch = int(input("Enter your choice :")) if ch==1: val = int(input("Enter Item to Push :")) Push(S,val) elif ch==2: val = Pop(S) if val=="Underflow": print("Stack is Empty")
  • 3. else: print(val) ''' elif ch==3: print("nDeleted Item was :",val) val = Peek(S) if val=="Underflow": print("Stack Empty") else: print(val) ''' elif ch==4: print("Top Item :",val) Show(S) elif ch==0: print("Bye") break