summaryrefslogtreecommitdiff
path: root/05/src/stack.rs
diff options
context:
space:
mode:
Diffstat (limited to '05/src/stack.rs')
-rw-r--r--05/src/stack.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/05/src/stack.rs b/05/src/stack.rs
new file mode 100644
index 0000000..ef42aab
--- /dev/null
+++ b/05/src/stack.rs
@@ -0,0 +1,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()
+ }
+}