updated filestructure and gitignore. uploading exam progress
This commit is contained in:
36
Exam/IKT203Exam/Portfolio/SharedLib/TStack.cpp
Normal file
36
Exam/IKT203Exam/Portfolio/SharedLib/TStack.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user