pub struct Stack<T: Clone> { /* fields omitted */ }
Expand description
structure representing a stack
A stack is handled as a collection of nodes.
we specify the top node who himself specifies the previous node and so on.
create a new stack
this function returns a new stack with one node that has the value of val
pub fn push(&mut self, val: T)
push a new element to the stack
val
: the value for the new element to have
use stacking::stacks::Stack;
let mut stack: Stack<i32> = Stack::new();
stack.push(4);
assert_eq!(stack.pop(), Some(4));
pop the top element of the stack.
an Option<T>
for the value that the element had
use stacking::stacks::Stack;
let mut stack: Stack<i32> = Stack::new();
stack.push(4);
stack.push(5);
assert_eq!(stack.pop(), Some(5));
assert_eq!(stack.pop(), Some(4));
return the length of the stack
the length of the stack as a usize
use stacking::stacks::Stack;
let mut stack: Stack<i32> = Stack::new();
stack.push(5);
assert_eq!(stack.len(), 1);
stack.pop();
assert_eq!(stack.len(), 0);
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
impl<T> Any for T where
T: 'static + ?Sized,
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
impl<T, U> Into<U> for T where
U: From<T>,
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.