/** * Tree test driver * CS 2240 * University of Vermont * Clayton Cafiero * 2020-Jun-20 */ #include #include "binaryTree.h" using Iter = std::vector::const_iterator; int main() { Node* a = new Node("A"); BinaryTree binTree = BinaryTree(a); Node* b = new Node("B"); Node* c = new Node("C"); Node* d = new Node("D"); Node* e = new Node("E"); Node* f = new Node("F"); Node* g = new Node("G"); Node* h = new Node("H"); Node* i = new Node("I"); Node* j = new Node("J"); a->setLeftChild(b); a->setRightChild(c); assert(a->getLabel() == "A"); assert(b->getLabel() == "B"); assert(c->getLabel() == "C"); assert(a->getLeftChild() == b); assert(a->getRightChild() == c); b->setLeftChild(d); b->setRightChild(e); c->setLeftChild(f); c->setRightChild(g); d->setLeftChild(h); d->setRightChild(i); e->setRightChild(j); std::cout << "DFS pre-order: "; std::vector v = binTree.preorder(); assert (std::find(v.begin(), v.end(), "A") != v.end()); for(Iter it = v.begin(); it != v.end(); it++) { std::cout << *it; } std::cout << std::endl; std::cout << "DFS post-order: "; v = binTree.postorder(); for(Iter it = v.begin(); it != v.end(); it++) { std::cout << *it; } std::cout << std::endl; std::cout << "DFS in-order: "; v = binTree.inorder(); for(Iter it = v.begin(); it != v.end(); it++) { std::cout << *it; } std::cout << std::endl; std::cout << "BFS: "; v = binTree.bfs(); for(Iter it = v.begin(); it != v.end(); it++) { std::cout << *it; } std::cout << std::endl; return 0; }