📄 pex11_9.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "treenode.h"
#include "treelib.h"
#include "treeprnt.h"
#include "bstree.h"
#include "wex11_18.h"
void main(void)
{
// create a binary search tree with data values from a
BinSTree<int> tree;
int a[] = {50,35,38,45,32,25,75,65,90,77};
int i, target;
TreeNode<int> *newtree;
// build the search tree
for(i=0;i < 10;i++)
tree.Insert(a[i]);
// print the search tree
PrintVTree(tree.GetRoot(),2,50);
cout << endl << endl << endl;
// enter a target, use TCopyTree to copy the tree
// and print the new tree vertically
cout << "Enter the target: ";
cin >> target;
newtree= TCopyTree(tree.GetRoot(),target);
PrintVTree(newtree,2,50);
}
/*
<Run #1>
50
35 75
32 38 65 90
25 45 77
Enter the target: 40
50
35 75
65 90
77
<Run #2>
50
35 75
32 38 65 90
25 45 77
Enter the target: 77
50
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -