本文整理汇总了C++中BinaryTree::InsertNode方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::InsertNode方法的具体用法?C++ BinaryTree::InsertNode怎么用?C++ BinaryTree::InsertNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::InsertNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createBinaryTree
BinaryTree* createBinaryTree()
{
BinaryTree* root = new BinaryTree(50);
root->InsertNode(10);
root->InsertNode(5);
root->InsertNode(20);
root->InsertNode(8);
/* root->InsertNode(100);
root->InsertNode(40);
root->InsertNode(6);
root->InsertNode(4);
root->InsertNode(70);*/
return root;
}
示例2: main
/************************************* MAIN FUNCTION *************************************/
int main()
{
//#7 Create a binary tree call b and insert nodes m,a,q
//Create a binary tree called 'b'
BinaryTree * b = new BinaryTree();
char m = 'm', a = 'a', q = 'q';
//insertNodes 'm','a','q' in this specific order
b->InsertNode(m);
b->InsertNode(a);
b->InsertNode(q);
//#8 call recurisve and non recursive functions of order types
//call both postorderR and postorder
std::cout << "Postorder: ";
b->Postorder();
std::cout << std::endl;
std::cout << "PostorderR: ";
b->PostorderR(b->GetRoot());
std::cout << std::endl;
//call both inorderR and inorder
std::cout << "Inorder: ";
b->Inorder();
std::cout << std::endl;
std::cout << "InorderR: ";
b->InorderR(b->GetRoot());
std::cout << std::endl;
//call both preorderR and preorder
std::cout << "Preorder: ";
b->Preorder();
std::cout << std::endl;
std::cout << "PreorderR: ";
b->PreorderR(b->GetRoot());
std::cout << std::endl;
std::system("pause");
return 1;
}
示例3: main
int main() {
BinaryTree* tree = new BinaryTree();
tree->InsertNode("A");
tree->InsertNode("B");
tree->InsertNode("C");
tree->InsertNode("D");
tree->InsertNode("E");
tree->InsertNode("F");
tree->InsertNode("G");
tree->InsertNode("H");
tree->InsertNode("I");
tree->InsertNode("J");
tree->InsertNode("K");
tree->InsertNode("L");
cout << "Pre order traversal" << endl;
tree->PreOrder(tree->root);
cout << endl;
cout << "In order traversal" << endl;
tree->InOrder(tree->root);
cout << endl;
cout << "Post order traversal" << endl;
tree->PostOrder(tree->root);
cout << endl;
cin.get();
return 0;
}