KnowledgeBoat Logo

Computer Science

Write an algorithm to pop an element from the Stack.

Python Stack

1 Like

Answer

An algorithm to pop an element from the Stack is as follows:

  1. START
  2. St_len = len(Stack) #Count the total number of elements in the Stack and checks whether the Stack is empty or not
  3. if St_len == []: or if not Stack: or If not len(Stack):
    print("Stack is empty")
    go to step 6
  4. element = Stack.pop() #Removing last element from top of the Stack
  5. print(element)
  6. END

Answered By

1 Like


Related Questions