package mantra.util.collections

Stack

CLASS public class Stack

LIFO (Last-In-First-Out) dynamic collection container supporting constant-time push, pop, and peek operations.

🏗️ Constructor Summary

Constructor Signature
def __init__(self)

⚙️ Method Summary

Modifier & Return Type Method Signature Description
Void push(item: T) Pushes element onto the top of the stack.
T pop() Removes and returns top element from stack.
T peek() Returns top element without removal.
Int size() Returns count of active elements in stack.

🔍 Detailed Method Specifications

pub def push(item: T) -> Void
Pushes element onto the top of the stack.
pub def pop() -> T
Removes and returns top element from stack.
pub def peek() -> T
Returns top element without removal.
pub def size() -> Int
Returns count of active elements in stack.

💡 Example Usage

stack_example.mantra
let s = Stack()
s.push("Task 1")
s.push("Task 2")
print(s.pop()) # Task 2