Check sibling questions

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

 

 


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

  1. Computer Science - Class 12
  2. Chapter 3 - Stacks

About the Author

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 and Computer Science at Teachoo