fixed indented bst printing
This commit is contained in:
parent
a74b3e2aca
commit
def78cb76f
17
BinaryTree.h
17
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<T>* nodePtr) const;
|
||||
|
||||
void _printindented(void visit(const T&, int), BinaryTreeNode<T>* nodePtr) const;
|
||||
void _printTree(void visit(const T&, int), BinaryTreeNode<T>* nodePtr, int level) const;
|
||||
|
||||
};
|
||||
|
||||
@ -95,13 +95,14 @@ void BinaryTree<T>::_postorder(void visit(const T&), BinaryTreeNode<T>* nodePtr)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void BinaryTree<T>::_printindented(void visit(const T&, int), BinaryTreeNode<T>* nodePtr) const {
|
||||
template<class T>
|
||||
void BinaryTree<T>::_printTree(void visit(const T&, int), BinaryTreeNode<T>* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
6
CPU.cpp
6
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<int> &widths) {
|
||||
|
2
CPU.h
2
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<int> &widths);
|
||||
|
||||
|
2
main.cpp
2
main.cpp
@ -122,7 +122,7 @@ void processInput(char command, HashTable<CPU> &cpuTable, BinarySearchTree<strin
|
||||
cout << "Longest collision path: " << cpuTable.getMaxCollisions() << std::endl;
|
||||
break;
|
||||
case 'P': // Print indented tree
|
||||
throw std::logic_error("Not yet implemented: Print indented tree");
|
||||
cpuTree.printTree(iDisplay);
|
||||
break;
|
||||
case 'Z': // Display names of team members
|
||||
printTeam();
|
||||
|
Loading…
x
Reference in New Issue
Block a user