diff --git a/BinaryTree.h b/BinaryTree.h index 59842aa..29d6527 100644 --- a/BinaryTree.h +++ b/BinaryTree.h @@ -28,7 +28,7 @@ public: void postOrder(void visit(const T&)) const { _postorder(visit, root); } - void printIndented(void visit(const T&)) const { _printindented(visit, root, 0); } + void printTree(void visit(const T&, int)) const { _printTree(visit, rootPtr, 1); } // abstract functions to be implemented by derived class virtual void insert(const T& newData) = 0; @@ -46,7 +46,7 @@ private: void _postorder(void visit(const T&), BinaryTreeNode* nodePtr) const; - void _printindented(void visit(const T&, int), BinaryTreeNode* nodePtr) const; + void _printTree(void visit(const T&, int), BinaryTreeNode* nodePtr, int level) const; }; @@ -95,13 +95,14 @@ void BinaryTree::_postorder(void visit(const T&), BinaryTreeNode* nodePtr) } } -template -void BinaryTree::_printindented(void visit(const T&, int), BinaryTreeNode* nodePtr) const { +template +void BinaryTree::_printTree(void visit(const T&, int), BinaryTreeNode* nodePtr, int level) const +{ if (nodePtr) { - T item = nodePtr->getItem(); - _printInnerNodes(visit, nodePtr->getLeftPtr()); - if (nodePtr->getLeftPtr() || nodePtr->getRightPtr()) visit(item); - _printInnerNodes(visit, nodePtr->getRightPtr()); + ItemType item = nodePtr->getItem(); + visit(item, level); + _printTree(visit, nodePtr->getRightPtr(), level + 1); + _printTree(visit, nodePtr->getLeftPtr(), level + 1); } } diff --git a/CPU.cpp b/CPU.cpp index e2e3aee..186a403 100644 --- a/CPU.cpp +++ b/CPU.cpp @@ -52,10 +52,10 @@ void display(const CPU &cpu) { printTableFooter(widths); } -void iDisplay(const CPU &cpu, int level) { +void iDisplay(const string &cpuId, int level) { for (int i = 0; i < level; i++) - cout << " "; - cout << cpu.cpuId << endl; + cout << ".."; + cout << level << ")." << cpuId << endl; } void rowDisplay(const CPU &cpu, const vector &widths) { diff --git a/CPU.h b/CPU.h index 5fa1f1d..5e965e2 100644 --- a/CPU.h +++ b/CPU.h @@ -74,7 +74,7 @@ public: void display(const CPU &cpu); -void iDisplay(const CPU &cpu, int level); +void iDisplay(const string &cpuId, int level); void rowDisplay(const CPU &cpu, const std::vector &widths); diff --git a/main.cpp b/main.cpp index 92af55e..b0c9cda 100644 --- a/main.cpp +++ b/main.cpp @@ -122,7 +122,7 @@ void processInput(char command, HashTable &cpuTable, BinarySearchTree