本文整理汇总了C++中BinaryTree::inorder方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::inorder方法的具体用法?C++ BinaryTree::inorder怎么用?C++ BinaryTree::inorder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::inorder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
BinaryTree tree;
vector <double> vect;
tree.insert(12);
tree.insert(7);
tree.insert(9);
tree.insert(10);
tree.insert(22);
tree.insert(22);
tree.insert(24);
tree.insert(30);
tree.insert(18);
tree.insert(3);
tree.insert(14);
tree.insert(20);
tree.inorder(vect);
for (int i = 0; i < vect.size(); i++)
cout << vect[i] << " ";
cout << endl;
if (tree.search(3.1))
cout << "3.1 was found in the tree.\n";
else
cout << "3.1 was not found in the tree.\n";
cout << "Size of vect: " << tree.size() << endl;
cout << "Leaf count of vect: " << tree.leafCount() << endl;
return 0;
}
示例2: main
int main()
{
BinaryTree tree;
vector<double> treeValues;
tree.insert(5.2);
tree.insert(8.6);
tree.insert(3.1);
tree.insert(12.9);
tree.insert(9.7);
if (tree.search(3))
cout << "3 was found in tree.\n";
else
cout << "3 was not found in tree.\n";
tree.inorder(treeValues);
for (int i = 0; i < treeValues.size(); i++)
{
cout << treeValues[i] << " ";
}
cout << endl;
return 0;
}
示例3: BT_depth_first
void BT_depth_first()
{
BinaryTree<int> T;
T.insert(5);
T.insert(104);
T.insert(2);
T.insert(3);
T.insert(10);
T.insert(130);
T.insert(60);
T.insert(9);
T.insert(78);
T.insert(11);
T.insert(8);
cout << "BinaryTree inorder traverse" << endl;
T.inorder();
/* You see the depth-first traverse result
* is ordered
*/
cout << "BinaryTree depth-first traverse" << endl;
T.depth_first();
}
示例4: BT_traverse
void BT_traverse()
{
BinaryTree<int> T;
create_bt(&T);
cout << "BinaryTree inorder traverse" << endl;
T.inorder();
}
示例5: timeInorder
void timeInorder(int size, int iter, bool linear, bool recur)
{
BinaryTree<int> bt;
// different tree structure depending on function parameters
if (linear) bt = generateLinkedList(size);
else bt = generateCompleteTree(size);
// time for iter iterations
clock_t start = clock();
// different method called depending on test type
if (recur) {
// do iter iterations
for (int i = 0; i <iter; ++i) {
deque<BinaryTree<int>::NodePtr> d;
bt.recursiveInorder(d,bt.getRoot());
}
}
else {
// do iter iterations
for (int i = 0; i <iter; ++i) {
deque<BinaryTree<int>::NodePtr> d;
bt.inorder(d,bt.getRoot());
}
}
clock_t end = clock();
double avg = double(end - start) / double(CLOCKS_PER_SEC) / iter;
// print out test params/results
string test_type = "InO ";
if (linear) test_type += "Lin ";
else test_type += "Bal ";
if (recur) test_type += "Re ";
else test_type += "It ";
cout << test_type << size << ' ' << iter << ' ' << setprecision(10) << avg << endl;
}
示例6: Binarytree_old_test
int Binarytree_old_test() {
BinaryTree binarytree;
binarytree.build_demo();
binarytree.preorder();
std::cout << std::endl;
binarytree.inorder();
std::cout << std::endl;
binarytree.postorder();
std::cout << std::endl;
return 0;
}
示例7: 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;
}