From 3edbc1aa0696a3809754c81d05fe24e537712e1c Mon Sep 17 00:00:00 2001 From: LaEntropiaa Date: Sun, 15 Mar 2026 20:57:13 -0600 Subject: [PATCH] constructor and destructor --- include/stack.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/main.cpp | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/stack.h b/include/stack.h index df6982b..51b7a05 100644 --- a/include/stack.h +++ b/include/stack.h @@ -1,8 +1,51 @@ #ifndef STACK_H #define STACK_H -class Stack { +#include +#include +#define DEFAULT_STACK_SIZE 4 + +enum class StackErr { + ok, + bad_alloc, + empty, }; +template +class Stack { +private: + uint64_t len; + uint64_t cap; + T *data; + +public: + Stack(); + ~Stack(); + + std::expected pop(); + + std::expected peek(); + + StackErr push(T val); + + void print(); +}; + +template +Stack::Stack() { + Stack new_stack; + new_stack.data = new T[DEFAULT_STACK_SIZE]; + new_stack.cap = 0; + new_stack.len = 0; + return new_stack; +} + +template +Stack::~Stack() { + delete[] this->data; +} + + + #endif // !ST diff --git a/src/main.cpp b/src/main.cpp index bb7c2e7..6952221 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include "stack" #include int main(void) {