int main(int argc, char* argv[]) { if(argc < 2){ cout << "Incorrect arguments\n"; } BinaryTree<int> tree = generateCompleteTree(atoi(argv[1])); // test preorder std::deque<BinaryTree<int>::NodePtr> traversal; tree.preorder(traversal, tree.getRoot()); }
int main() { BinaryTree<int> empty; BinaryTree<int> complete = generateCompleteTree(30); BinaryTree<int> list = generateLinkedList(100); // empty tree is empty assert(empty.isEmpty()); // size of complete tree assert(complete.getSize() == 31); // size of list assert(list.getSize() == 100); // depth of complete tree assert(complete.getDepth() == 4); // depth of list assert(list.getDepth() == 99); typedef BinaryTree<int>::NodeDeque traversal_type; // root is at the front of a preorder traversal traversal_type pre; complete.preorder(pre, complete.getRoot()); assert(pre.front() == complete.getRoot()); // root is at the end of a postorder traversal traversal_type post; complete.postorder(post, complete.getRoot()); assert(post.back() == complete.getRoot()); // root is in the middle of an inorder traversal traversal_type in; complete.inorder(in, complete.getRoot()); assert(in.at(in.size()/2) == complete.getRoot()); // traversals should contain all nodes of the tree assert(pre.size() == complete.getSize()); assert(post.size() == complete.getSize()); assert(in.size() == complete.getSize()); typedef BinaryTree<int>::NodePtr iterator; const int query_value = 22; // 22 should be in the list and complete tree iterator complete_query = complete.simpleSearch(query_value); iterator list_query = list.simpleSearch(query_value); iterator empty_query = empty.simpleSearch(query_value); assert(complete_query != NULL); assert(list_query != NULL); assert(empty_query == NULL); // test copy ctor and assignment operator BinaryTree<int> copied(complete); BinaryTree<int> assigned; assigned = complete; // should have same size assert(copied.getSize() == complete.getSize()); assert(assigned.getSize() == complete.getSize()); // should still have 22 iterator copy_query = copied.simpleSearch(query_value); iterator assign_query = assigned.simpleSearch(query_value); assert(copy_query != NULL); assert(assign_query != NULL); std::cout << "Passed!" << std::endl; return 0; }