Computer Science, asked by youarefuved, 6 months ago

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.

Answers

Answered by prakhars2558
6

Answer:

Explanation:

l = [1, 2, 3, 4, 5]

def pop(arr):

if len(arr) > 0:

rem_item = arr[-1]

del arr[-1]

return rem_item

print(pop(l))

Answered by priyarksynergy
0

Write a function for POP operation on a stack.

Explanation:

  • A stack is a linear data structure that follows FILO (First in last out ) or LIFO (Last in first out) rule.
  • This means that the data entered most recently in the stack is deleted first using the 'pop' operation.
  • When a stack is implemented using a python list then the first data entry is stored at zero index and so on.
  • Hence, the pop function should delete the data at the last index of the list.
  • In python programming language the data at a given index of a list can be removed using the "pop(index)" method offered by lists.
  • PROGRAM:
  • def POP(Arr):
  •    temp= Arr[-1]
  •    Arr.pop(-1)
  •    return temp

Similar questions