Struct stacking::stack::stacks::Stack[][src]

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.

Implementations

create a new stack

Arguments

  • val: the value to use

Returns

this function returns a new stack with one node that has the value of val

push a new element to the stack

Arguments

val: the value for the new element to have

Examples

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.

Returns

an Option<T> for the value that the element had

Examples

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

Returns

the length of the stack as a usize

Examples

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);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

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.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.