Stack Implementation Using List
Stack Implementation Using List
def makepush(package):
package.append(a)
def makepop(package):
if package==[]:
else:
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