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

 

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class


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

Ask a doubt
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 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.