Add project files

This commit is contained in:
Kevin 2024-06-17 03:36:21 -07:00
parent 97923445d8
commit 30454d624c
6 changed files with 159 additions and 0 deletions

29
DisplayManager.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "DisplayManager.h"
#include <iostream>
DisplayManager::DisplayManager(HashTable* ht, BinarySearchTree* bst) {
this->hashTable = ht;
this->bst = bst;
}
DisplayManager::~DisplayManager() {
// No dynamic memory allocation, so no cleanup needed
}
void DisplayManager::displayAll() const {
std::cout << "All CPUs in the database:" << std::endl;
// Iterate over the HashTable and display each CPU
for (int i = 0; i < hashTable->getSize(); i++) {
if (hashTable->getItem(i) != nullptr) {
std::cout << *(hashTable->getItem(i)) << std::endl;
}
}
}
void DisplayManager::displayTree() const {
std::cout << "CPU Binary Search Tree:" << std::endl;
// Call the BST's inorder traversal method to display the tree
bst->inorderTraversal();
}

22
DisplayManager.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef DISPLAY_MANAGER_H
#define DISPLAY_MANAGER_H
#include "HashTable.h"
#include "BinarySearchTree.h"
#include "CPU.h"
template<typename T>
class DisplayManager {
private:
HashTable* hashTable;
BinarySearchTree* bst;
public:
DisplayManager(HashTable* ht, BinarySearchTree* bst);
~DisplayManager();
void displayAll() const;
void displayTree() const;
};
#endif

27
SearchManager.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "SearchManager.h"
#include <iostream>
#include <string>
SearchManager::SearchManager(HashTable* ht) {
this->hashTable = ht;
}
SearchManager::~SearchManager() {
// No dynamic memory allocation, so no cleanup needed
}
void SearchManager::searchCPU() const {
std::string cpuID;
std::cout << "Enter the CPU ID to search: ";
std::cin >> cpuID;
// Search for the CPU in the HashTable
CPU* foundCPU = hashTable->search(cpuID);
if (foundCPU != nullptr) {
std::cout << "CPU found:" << std::endl;
std::cout << *foundCPU << std::endl;
} else {
std::cout << "CPU not found." << std::endl;
}
}

19
SearchManager.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef SEARCH_MANAGER_H
#define SEARCH_MANAGER_H
#include "HashTable.h"
#include "CPU.h"
template<typename T>
class SearchManager {
private:
HashTable* hashTable;
public:
SearchManager(HashTable* ht);
~SearchManager();
void searchCPU() const;
};
#endif

37
UndoManager.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "UndoManager.h"
#include <iostream>
UndoManager::UndoManager(HashTable* ht, BinarySearchTree* bst) {
this->hashTable = ht;
this->bst = bst;
this->undoStack = new Stack<CPU>();
}
UndoManager::~UndoManager() {
delete undoStack;
}
void UndoManager::addToUndoStack(const CPU& cpu) {
undoStack->push(cpu);
}
void UndoManager::undoDelete() {
if (!undoStack->isEmpty()) {
CPU lastDeleted = undoStack->pop();
// Reinsert the CPU into the HashTable and BST
hashTable->insert(lastDeleted);
bst->insert(lastDeleted);
std::cout << "Undo successful. CPU reinserted:" << std::endl;
std::cout << lastDeleted << std::endl;
} else {
std::cout << "No deletions to undo." << std::endl;
}
}
void UndoManager::clearUndoStack() {
while (!undoStack->isEmpty()) {
undoStack->pop();
}
}

25
UndoManager.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef UNDO_MANAGER_H
#define UNDO_MANAGER_H
#include "HashTable.h"
#include "BinarySearchTree.h"
#include "Stack.h"
#include "CPU.h"
template<typename T>
class UndoManager {
private:
HashTable* hashTable;
BinarySearchTree* bst;
Stack<CPU>* undoStack;
public:
UndoManager(HashTable* ht, BinarySearchTree* bst);
~UndoManager();
void addToUndoStack(const CPU& cpu);
void undoDelete();
void clearUndoStack();
};
#endif