Stack
A generic stack data structure.
Usage
Stack()Parameters
items: Optional[List[T]] = None-
Initial items for the stack.
Methods
| Name | Description |
|---|---|
| is_empty() | Check if the stack is empty. |
| peek() | View the top item without removing it. |
| pop() | Pop the top item from the stack. |
| push() | Push an item onto the stack. |
is_empty()
Check if the stack is empty.
Usage
is_empty()Returns
bool-
True if empty.
peek()
View the top item without removing it.
Usage
peek()Returns
T-
The top item.
pop()
Pop the top item from the stack.
Usage
pop()Returns
T-
The item removed from the top.
Raises
IndexError-
If the stack is empty.
push()
Push an item onto the stack.
Usage
push(item)Parameters
item: T-
Item to push.