Computer Science - Class 12
Chapter 3 - Stacks

Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack.

Answer:

def POP(Arr):

top=len(Arr)-1

if len(Arr)!=0:

deleted_val=Arr[top]

Arr.pop()

else:

print("Stack is Empty")

return deleted_val

 

Slide27.JPG

 


Transcript

Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack. Answer: def POP(Arr): top=len(Arr)-1 if len(Arr)!=0: deleted_val=Arr[top] Arr.pop() else: print("Stack is Empty") return deleted_val

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.