diff --git a/DisplayManager.cpp b/DisplayManager.cpp new file mode 100644 index 0000000..29bed2c --- /dev/null +++ b/DisplayManager.cpp @@ -0,0 +1,29 @@ +#include "DisplayManager.h" +#include + +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(); +} \ No newline at end of file diff --git a/DisplayManager.h b/DisplayManager.h new file mode 100644 index 0000000..83a1b51 --- /dev/null +++ b/DisplayManager.h @@ -0,0 +1,22 @@ +#ifndef DISPLAY_MANAGER_H +#define DISPLAY_MANAGER_H + +#include "HashTable.h" +#include "BinarySearchTree.h" +#include "CPU.h" + +template +class DisplayManager { +private: + HashTable* hashTable; + BinarySearchTree* bst; + +public: + DisplayManager(HashTable* ht, BinarySearchTree* bst); + ~DisplayManager(); + + void displayAll() const; + void displayTree() const; +}; + +#endif \ No newline at end of file diff --git a/SearchManager.cpp b/SearchManager.cpp new file mode 100644 index 0000000..8e642c3 --- /dev/null +++ b/SearchManager.cpp @@ -0,0 +1,27 @@ +#include "SearchManager.h" +#include +#include + +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; + } +} \ No newline at end of file diff --git a/SearchManager.h b/SearchManager.h new file mode 100644 index 0000000..2198acf --- /dev/null +++ b/SearchManager.h @@ -0,0 +1,19 @@ +#ifndef SEARCH_MANAGER_H +#define SEARCH_MANAGER_H + +#include "HashTable.h" +#include "CPU.h" + +template +class SearchManager { +private: + HashTable* hashTable; + +public: + SearchManager(HashTable* ht); + ~SearchManager(); + + void searchCPU() const; +}; + +#endif \ No newline at end of file diff --git a/UndoManager.cpp b/UndoManager.cpp new file mode 100644 index 0000000..218c2bb --- /dev/null +++ b/UndoManager.cpp @@ -0,0 +1,37 @@ +#include "UndoManager.h" +#include + +UndoManager::UndoManager(HashTable* ht, BinarySearchTree* bst) { + this->hashTable = ht; + this->bst = bst; + this->undoStack = new Stack(); +} + +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(); + } +} \ No newline at end of file diff --git a/UndoManager.h b/UndoManager.h new file mode 100644 index 0000000..6239cf3 --- /dev/null +++ b/UndoManager.h @@ -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 +class UndoManager { +private: + HashTable* hashTable; + BinarySearchTree* bst; + Stack* undoStack; + +public: + UndoManager(HashTable* ht, BinarySearchTree* bst); + ~UndoManager(); + + void addToUndoStack(const CPU& cpu); + void undoDelete(); + void clearUndoStack(); +}; + +#endif \ No newline at end of file