1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#[derive(Clone)] pub struct Stack<T> { data: Vec<T> } impl<T> Stack<T> { pub fn new() -> Self { Self { data: Vec::new() } } pub fn clear(self: &mut Self) { self.data.clear(); } pub fn push(self: &mut Self, x: T) { self.data.push(x) } pub fn peek(self: & Self) -> Option<& T> { self.data.last() } pub fn pop(self: &mut Self) -> Option<T> { self.data.pop() } }