From 9d9bd35065ded1d78c9a07af2953e69fc8eb61d4 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 8 Jan 2023 22:35:13 +0200 Subject: [SDP/HEP] Added preparation for "homework" during class --- .../HomeworkExamPrep/Stack/Stack_Static.hpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp (limited to 'Year 2/Structures and data algorithms/HomeworkExamPrep/Stack/Stack_Static.hpp') 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 Stack { + T vals[STACK_SIZE]; + unsigned topPos = 0; + +public: + void push(const T& v); + void pop(); + T& top(); +}; + +template +void Stack::push(const T& v) { + vals[topPos++] = v; +} + +template +void Stack::pop() { + topPos--; +} + +template +T& Stack::top() { + return vals[topPos - 1]; +} + +#endif -- cgit v1.3.1-23-gd82d