Struct ripin::Stack [] [src]

pub struct Stack<T>(_);

A growable stack implementing push/pop actions.

use ripin::Stack;

let mut stack = Stack::new();

stack.push(3);
stack.push(4);
stack.push(10);
assert_eq!(stack.len(), 3);

assert_eq!(stack.pop(), Some(10));
assert_eq!(stack.len(), 2);

Methods

impl<T> Stack<T>
[src]

Creates an empty VecDeque.

Examples

use ripin::Stack;

let mut stack: Stack<i32> = Stack::new();

Creates an empty VecDeque with space for at least n elements.

Examples

use ripin::Stack;

let mut stack: Stack<i32> = Stack::with_capacity(10);

Returns the number of elements in the set.

Examples

use ripin::Stack;

let mut stack = Stack::new();
stack.push(3);
assert_eq!(stack.len(), 1);

Returns true if the set contains no elements.

Examples

use ripin::Stack;

let mut stack = Stack::new();
assert_eq!(stack.is_empty(), true);
stack.push(3);
assert_eq!(stack.is_empty(), false);

Appends an element to the back of the stack.

Panics

Panics if the number of elements in the stack overflows a usize.

Examples

use ripin::Stack;

let mut stack = Stack::new();
stack.push(3);
assert_eq!(stack.pop(), Some(3));
assert_eq!(stack.pop(), None);

Removes the last element from the stack and returns it, or None if it is empty.

Examples

use ripin::Stack;

let mut stack = Stack::new();
stack.push(3);
stack.push(2);
assert_eq!(stack.pop(), Some(2));
assert_eq!(stack.pop(), Some(3));
assert_eq!(stack.pop(), None);