📄 wex11_27.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "treelib.h"
#include "treescan.h"
#include "bstree.h"
#include "strclass.h"
// print the String data in a tree node
void print(String& s)
{
cout << s << endl;
}
void main(void)
{
// construct a binary search tree of String data whose data
// values are build from array a
BinSTree<String> tree;
String a[] = {"for", "case", "while", "class", "protected",
"virtual", "public", "private", "do", "template",
"const", "if", "int"};
// create tree and print it
for(int i=0;i < 13;i++)
tree.Insert(a[i]);
// traverse the tree in all primary orders
cout << "Preorder:" << endl;
Preorder(tree.GetRoot(),print);
cout << endl << endl;
cout << "Postorder:" << endl;
Postorder(tree.GetRoot(),print);
cout << endl << endl;
cout << "Inorder:" << endl;
Inorder(tree.GetRoot(),print);
cout << endl << endl;
}
/*
<Run>
Preorder:
for
case
class
do
const
while
protected
private
if
int
virtual
public
template
Postorder:
const
do
class
case
int
if
private
template
public
virtual
protected
while
for
Inorder:
case
class
const
do
for
if
int
private
protected
public
template
virtual
while
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -