elixir_ds v0.1.0 ElixirDS.Deque View Source
Double Ended Queue.
Supports O(1) (amortized) insertions and deletions at both ends
TODO: Add usage instructions
API
- [x] new()
- [x] from_list(lst)
- [x] is_empty(q)
- [x] size(q)
- [x] push_front(q, elem)
- [x] push_back(q, elem)
- [x] pop_front(q)
- [x] pop_back(q)
- [x] peek_front(q)
- [x] peek_back(q)
- [x] rotate(q, n)
Link to this section Summary
Functions
Create a new deque from a list
Is the deque empty?
Create a new deque
Peek the last element in the queue
Peek the first element in the queue
Removes the value at the back of the deque and retuns the value and the updated deque
Removes the value at the front of the deque and retuns the value and the updated deque
Insert a value at the back of the deque
Insert a value at the front of the deque
Rotates the list by n elements (front to back). In case n is negative, moves the items in the other direction
Get the number of elements in the deque
Link to this section Types
Link to this section Functions
from_list(lst) View Source
Create a new deque from a list.
is_empty?(dq) View Source
Is the deque empty?
new()
View Source
new() :: t()
new() :: t()
Create a new deque.
peek_back(deque) View Source
Peek the last element in the queue.
This function does not modify the deque.
In case the queue is empty, it will return an :error
.
peek_front(deque) View Source
Peek the first element in the queue.
This function does not modify the deque.
In case the queue is empty, it will return an :error
.
pop_back(dq) View Source
Removes the value at the back of the deque and retuns the value and the updated deque.
pop_front(dq) View Source
Removes the value at the front of the deque and retuns the value and the updated deque.
push_back(dq, val) View Source
Insert a value at the back of the deque.
push_front(dq, val) View Source
Insert a value at the front of the deque.
rotate(dq, n) View Source
Rotates the list by n elements (front to back). In case n is negative, moves the items in the other direction
size(deque)
View Source
size(t()) :: non_neg_integer()
size(t()) :: non_neg_integer()
Get the number of elements in the deque.