本文整理汇总了C++中BinaryTree::getDepth方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::getDepth方法的具体用法?C++ BinaryTree::getDepth怎么用?C++ BinaryTree::getDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::getDepth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}