Cleaning up and adding comments

This commit is contained in:
Christopher Sanden
2025-11-18 13:23:54 +01:00
parent d1fa8eda6b
commit e77d7ff21e
14 changed files with 202 additions and 103 deletions

View File

@@ -3,25 +3,24 @@
#ifndef OPTION1_H
#define OPTION1_H
#include <iostream>
#include <TTreeQueue.h>
#include <unordered_set>
#include "TAVL.h"
#include "TBST.h"
#include "TEmployee.h"
#include "Utils.h"
#include "../../Submissions/Submission-04/BankAccount.h"
/// To keep track of used ID values to ensure
/// all unique IDs
// Global state for Category 3, Option 1:
// - bst: owns all TEmployee objects (deleted in TBST destructor)
// - avl: separate AVL tree used only to demonstrate balancing on int keys
inline std::unordered_set<int> usedIds;
static TBST* bst;
static TAVL* avl;
int RunApp();
// Assign a unique random employee ID in the range [1, 1000].
// Uses 'usedIds' to avoid duplicates so the BST always has unique keys.
inline void IdGenerator(TEmployee* employee)
{
int id = Utils::RandomInt(1, 1000);
@@ -32,6 +31,11 @@ inline void IdGenerator(TEmployee* employee)
usedIds.insert(id);
employee->id = id;
}
// Callback used by readNamesFromFile.
// - Creates a new TEmployee from the given name.
// - Stops after 200 employees (as required by the assignment).
// - Generates a unique ID and inserts the employee into the BST.
static bool onNameRead(const int index, const int aTotalCount, const std::string& aFirstName, const std::string& aLastName)
{
const auto e = new TEmployee(aFirstName, aLastName);
@@ -50,6 +54,7 @@ inline void printline()
std::cout << "----------------------------------------" << std::endl;
}
// Helper to visually separate different demos (traversals, search, etc.) in the console output.
inline void pack(const std::string& line)
{
std::cout << "\n\n\n" << std::endl;