CBSE · 083Class XII · 2022Section A2 marks

Question 01

7 June 2022 · Computer Science (083)

"Stack is a linear data structure which follows a particular order in which the operations are performed."

- What is the order in which the operations are performed in a Stack ? - Name the List method/function available in Python which is used to remove the last element from a list-implemented stack. - Also write an example using Python statements for removing the last element of the list.

Answer

Order of operations performed in a Stack is LIFO (Last In First Out).

The List method in Python used to remove the last element from a list-implemented stack is pop() (or pop(-1)).

Example :

python
L = [10, 20, 30, 40]
L.pop()        # OR L.pop(-1)

Explanation

A stack is a LIFO data structure — the most recently pushed element is the first one popped. Python's list.pop() with no argument removes and returns the last element, mirroring stack pop. (FILO — First In Last Out — is also accepted.)