0% found this document useful (0 votes)
48 views4 pages

Stack Implementation Using List

Uploaded by

Anjneya Vasu X B
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)
48 views4 pages

Stack Implementation Using List

Uploaded by

Anjneya Vasu X B
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
You are on page 1/ 4

STACK IMPLEMENTATION USING LIST

 Write a function in Python makepush(package) and makepop(package)


to add a new package and delete a package from a list of packages
considering them to perform push and pop operation of stack.

def makepush(package):

a=input(“Enter package description :”)

package.append(a)

def makepop(package):

if package==[]:

print(“Underflow Case…Stack is Empty”)

else:

print(“Deleted Element is :”,package.pop())

 Write push(book) and pop(book) methods / functions in Python to add


a new book and delete a book from a list book title, considering them
to act as push and pop operations of stack data structure.

def push(book):
a=input(“Enter Book Title:”)
book.append(a)
def pop(book):
if book==[]:
print(“Underflow Case…Stack is Empty”)
else:
print(“Deleted Element is :”,book.pop())


 Write a function in Python push(package) and pop(package) to add
details of employee containing information (empid, empname, salary)
in the form of a Tuple in package and delete a package from a list of
package description considering them to act as push and pop
operation.
def push(package):
empid=int(input(“Enter Employee ID:”))
empname=input(“Enter Enployee Name:”)
salary=int(input(“Enter Salary”))
t=(empid.empname,salary)
package.append(t)
def pop(package):
if package==():
print(“Underflow Case”)
else:
print(“Deleted Element :”, package.pop())
===========================================================
#IMPLEMENTATION OF STACK OPERATION USING LIST.
stack=[]
n=0
def push(stk,elt):
stk.append(elt)
print("Element Inserted InTo Stack")
print(stk)
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def pop(stk):
if isEmpty(stk)==True:
print("Stack is Empty")
else:
print("Deteted Element:",stk.pop())
def peek(stk):
if isEmpty(stk):
print("Stack is Empty")
else:
print("Element On Top: ",stk[-1])
def display(stk):
a=stk[::-1]
print(a)
while True:
print(".......................................STACK
OPERATIONS.........................................")
print(" 1. PUSH ")
print(" 2. POP ")
print(" 3. PEEK ")
print(" 4. DISPLAY ")
print(" 5. EXIT ")
ch=int(input("Enter your choice (1 - 5) : "))
if ch==1:
n=int(input("Enter Element For Stack : "))
push(stack,n) #function calling
if ch==2:
pop(stack) #function calling
if ch==3:
peek(stack) #function calling
if ch==4:
display(stack) #function calling
if ch==5:
break

You might also like