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

47
Exam/part1/TQueue.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include "TQueue.h"
#include <stdexcept>
void TQueue::Enqueue(const std::string& text)
{
if (IsFull())
throw std::overflow_error("Queue Overflow");
queue[tail] = text;
tail = (tail + 1) % MAX_SIZE;
count++;
}
std::string TQueue::Dequeue()
{
if (IsEmpty())
throw std::underflow_error("Empty Queue");
const std::string item = queue[head];
head = (head + 1) % MAX_SIZE;
count--;
return item;
}
std::string TQueue::Peek() const
{
if (IsEmpty())
throw std::underflow_error("Empty Queue");
return queue[head];
}
bool TQueue::IsEmpty() const
{
return count == 0;
}
bool TQueue::IsFull() const
{
return count == MAX_SIZE;
}
int TQueue::GetTail() const
{
if (IsEmpty())
throw std::underflow_error("Empty Queue");
return tail;
}