Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Structures and data algorithms / HomeworkExamPrep / Stack / Stack_Static.hpp
diff options
context:
space:
mode:
1 files changed, 32 insertions, 0 deletions
-rw-r--r--Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp32
diff --git a/Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp b/Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp
new file mode 100644
index 0000000..91fdb65
--- /dev/null
+++ b/Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp
@@ -0,0 +1,32 @@
+#ifndef STACK_STATIC
+#define STACK_STATIC
+
+#define STACK_SIZE 1024
+
+template <class T>
+class Stack {
+ T vals[STACK_SIZE];
+ unsigned topPos = 0;
+
+public:
+ void push(const T& v);
+ void pop();
+ T& top();
+};
+
+template <class T>
+void Stack<T>::push(const T& v) {
+ vals[topPos++] = v;
+}
+
+template <class T>
+void Stack<T>::pop() {
+ topPos--;
+}
+
+template <class T>
+T& Stack<T>::top() {
+ return vals[topPos - 1];
+}
+
+#endif