structure v0.2.2 Structure.Stack View Source
A simple stack data structure. Supports push, pop and head operations.
Link to this section Summary
Functions
Checks if a given stack is empty
Creates a stack from a list
Returns the head of the stack
Returns a new empty stack
Pops top element from stack
Returns {:ok, stack}
for success, or {:error, :empty_stack}
if the stack
was empty
Pushes an item on the stack
Returns the size of a stack
Link to this section Types
Link to this section Functions
Checks if a given stack is empty
Examples
iex> Structure.Stack.empty?(%Structure.Stack{size: 0, list: []})
true
Creates a stack from a list.
Returns the head of the stack.
It should return {:ok, head}
.
If the stack is empty, it returns {:error, :empty_stack}
instead.
Examples
iex> Structure.Stack.head(%Structure.Stack{size: 0, list: []})
{:error, :empty_stack}
Returns a new empty stack.
Pops top element from stack
Returns {:ok, stack}
for success, or {:error, :empty_stack}
if the stack
was empty.
Pushes an item on the stack.
Returns the size of a stack.