Stack
A stack is a linear data structure that stores items
in a Last-In First-Out (LIFO) or manner. In stack, a
new element is added at one end and an element is
removed from that end only. The insert and delete
operations are often called push and pop.
Characteristics
i. LIFO Data structure
ii. Insertion and deletion from same end( from the
top of the stack)
Applications:
i. Undo feature in the editor. The Undo feature
works on the last event that we have done.
ii. Expression evaluation
iii. function call and return process.
Element insert : Push
Element delete : Pop
stack=[]
def PUSH(Arr):
for I in Arr:
if I%5==0:
[Link](I)
if len(stack)>0:
print(stack)
else:
print("Stack is empty")
L=[14,7,12,18,43,19,51]
PUSH(L)
OR
def POP(Arr):
for I in Arr:
return [Link]()
L=[14,7,12,18,43,19,51]
A=POP(L)
print("deleted element:",A)
R={"Aman":85,"Jai":60,"Bharat":92,"Suraj":74,"Tom":82
,"Ali":76}
stack=[]
def Push():
for I in R:
if R[I]>75:
[Link](I)
def Pop():
while len(stack)>0:
print([Link](),end= " ")
Push()
Pop()
OR
N=[11,15,12,18,99,50,17,26,40,41]
stack=[]
def Push():
for I in N:
if I%2==0:
[Link](I)
def Pop():
while len(stack)>0:
print([Link](), end=" ")
Push()
Pop()
customer=[["Gurdas",9852685555,"Goa"],["Julee",253524
53544,"Mumbai"],["Akash",553523535,"Goa"],["Abhay",25
3254555,"Delhi"]]
status=[]
def Push_element():
for I in customer:
if I[2]=="Goa":
[Link]([I[0],I[1]])
def Pop_element():
while len(status)>0:
print([Link]())
else:
print("Stack is empty")
Push_element()
Pop_element()
customer=[["Siddharth","Delux"],["rahul","Standard"],
["Ravi","Delux"]]
Hotel=[]
def Push_cust():
for I in customer:
if I[1]=="Delux":
[Link](I[0])
def Pop_cust():
while len(Hotel)>0:
print([Link]())
else:
print("Underflow")
Push_cust()
Pop_cust()
OR
vehicle={"Santro":"Hundai","Nexon":"TATA","Safari":"T
ata"}
stack=[]
def Push(vehicle):
A=0
for I in vehicle:
if vehicle[I].lower()=="tata":
[Link](I)
A=A+1
print(A)
Push(vehicle)