Introduction
Imagine you have a stack of plates on a table. You can only add or remove the top plate. This problem of managing items in a strict order is solved by a stack in computing.
Jump into concepts and practice - no test required
Think of a stack of books on a desk. You add new books on top and remove books only from the top. You cannot take a book from the middle without removing the ones above it first.
┌─────────┐ │ Top │ ← Newest item (last pushed) ├─────────┤ │ Item 3 │ ├─────────┤ │ Item 2 │ ├─────────┤ │ Item 1 │ └─────────┘ (push adds here, pop removes here)
last-in, first-out (LIFO) mean in the context of a stack?push to add items and pop to remove items.push adds an item to the stack, so Use the push operation is correct.push operation. -> Option Cpush(5)
push(3)
pop()
push(2)
pop()
pop()
pop() operation?stack = [] item = stack.pop()
[1, 2, 3, 4] using a stack. Which sequence of operations correctly reverses the list?