📄 pex11_2.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "treenode.h"
#include "treelib.h"
#include "bstree.h"
// traverse tree in RNL order
template <class T>
void RNL(TreeNode<T> *tree, void visit(T& item))
{
// if tree is NULL, return
if (tree != NULL)
{
// visit the right subtree
RNL(tree->Right(),visit);
// visit the node
visit(tree->data);
// visit the left subtree
RNL(tree->Left(),visit);
}
}
// print the character data in a tree node
void print (int& elem)
{
cout << elem << " ";
}
void main(void)
{
// we create binary search tree t
BinSTree<int> t;
int i,value;
// read 10 integer values and insert each into
// binary search tree t
for(i=0;i < 10;i++)
{
cin >> value;
t.Insert(value);
}
// traverse the tree in RNL order, printing each node
RNL(t.GetRoot(),print);
cout << endl;
}
/*
<Run>
45 27 4 5 18 78 9 3 5 55
78 55 45 27 18 9 5 5 4 3
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -