Struct stdlib_rs::collections::min_stack::MinStack [−][src]
pub struct MinStack<T: Ord>(_);
Expand description
A Stack data type that supports accessing the minimum item in the stack in O(1) time.
Implementations
Finds the minimum item of the stack in O(1) time.
If the stack is empty, returns None
.
Examples
let stack = min_stack![1, 2];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.min(), Some(1));
assert_eq!(empty.min(), None);
Look at the top item of the stack in O(1) time.
If the stack is empty, returns None
.
Examples
let stack = min_stack![1, 2];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.peek(), Some(2));
assert_eq!(empty.peek(), None);
Adds an item to the end of the stack in O(1) time.
Examples
let mut stack = min_stack![1];
stack.push(2);
assert_eq!(stack.len(), 2);
Extracts a slice containing the Min Stack.
Equivalent to &s[..]
.
Returns a mutable pointer to the min_stack.
Clears the MinStack, removing all values.
Examples
let mut stack = min_stack![1,2,3];
stack.clear();
assert_eq!(stack, min_stack![]);
Creates a new MinStack with the given capacity.
Examples
let stack: MinStack<i32> = MinStack::with_capacity(10);
assert!(stack.capacity() >= 10);
Reserves capacity for at least additional
more elements to be inserted
in the given MinStack<T>
. The collection may reserve more space to
avoid frequent reallocations. After calling reserve, capacity will be
greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
Examples
let mut stack = min_stack![1];
stack.reserve(10);
assert!(stack.capacity() >= 11);
Returns the number of elements the vector can hold without reallocating.
Examples
let stack: MinStack<i32> = MinStack::with_capacity(10);
assert!(stack.capacity() >= 10);
Removes the last element from a vector and returns it, or None
if it is empty.
Examples
let mut stack = min_stack![1, 2, 3];
let mut empty: MinStack<i32> = min_stack![];
assert_eq!(stack.pop(), Some(3));
assert_eq!(empty.pop(), None);
Returns true
if the MinStack has no elements.
Examples
let stack = min_stack![1, 2, 3];
let empty: MinStack<i32> = min_stack![];
assert_eq!(stack.is_empty(), false);
assert_eq!(empty.is_empty(), true);
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for MinStack<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for MinStack<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more