Adding exam part 1/4

This commit is contained in:
Christopher Sanden
2025-11-03 21:30:23 +01:00
parent d6e494cf1c
commit a8006be05f
95 changed files with 12245 additions and 25 deletions

36
Exam/part1/TStack.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "TStack.h"
#include <stdexcept>
void TStack::Push(const TAction& action)
{
if (top >= STACK_MAX_SIZE)
throw std::overflow_error("Stack overflow");
event[top++] = action;
}
TStack::TAction TStack::Pop()
{
if (top == 0)
throw std::underflow_error("Stack empty");
return event[--top];
}
TStack::TAction TStack::Peek() const
{
if (top == 0)
throw std::underflow_error("Stack empty");
return event[top - 1];
}
bool TStack::IsEmpty() const
{
return top == 0;
}
void TStack::Clear()
{
for (int i = 0; i < top; i++) {
this->Pop();
}
}