From 8ceb79db1d0687bba005cef4a77bb889bf7ec3c3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 9 Jan 2022 21:47:23 +0100 Subject: refactor: rewrite to c++ --- src/stack.hpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/stack.hpp (limited to 'src/stack.hpp') diff --git a/src/stack.hpp b/src/stack.hpp new file mode 100644 index 0000000..b156242 --- /dev/null +++ b/src/stack.hpp @@ -0,0 +1,43 @@ +#ifndef STACK_HPP +#define STACK_HPP + +#include + +/** + * A stack data structure. + */ +template +class Stack +{ +public: + /** + * Creates a stack. + * + * @param capacity The capacity of the stack + */ + Stack(int capacity); + + /** + * Pushes a item onto the stack. + */ + void push(Item item); + + /** + * Pops the topmost item from the stack. + */ + void pop(); + + /** + * Peeks into the stack. + * + * @returns The topmost stack item. + */ + Item peek(); + +private: + std::vector _items; +}; + +#include "stack.tpp" + +#endif -- cgit v1.2.3-18-g5258