CBSE Class 12 Computer Science Question 32 of 63

Data Structures in Python — Question 6

Back to all questions
6
Question

Question 6

Write an algorithm to pop an element from the Stack.

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