📄 wex11_13.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "treelib.h"
#include "treeprnt.h"
// make one of 5 character trees
void MakeCharTree2(TreeNode<char>* &root, int n)
{
// 9 TreeNode pointers; points to the 9 items in the tree
TreeNode<char> *a, *b, *c, *d, *e, *f, *g, *h, *i;
// parameter n specifies a tree in the range 0 - 4
switch(n)
{
// nodes D and E leaf nodes ; A is root node
case 0:
d = GetTreeNode('D');
e = GetTreeNode('E');
b = GetTreeNode('B',(TreeNode<char> *)NULL, d);
c = GetTreeNode('C',e, (TreeNode<char> *)NULL);
a = GetTreeNode('A',b, c);
root = a;
break;
// nodes E, G, H, and I leaf nodes ; A is root node
case 1:
g = GetTreeNode('G');
h = GetTreeNode('H');
i = GetTreeNode('I');
d = GetTreeNode('D');
e = GetTreeNode('E',g, (TreeNode<char> *)NULL);
f = GetTreeNode('F',h, i);
b = GetTreeNode('B',d, e);
c = GetTreeNode('C',(TreeNode<char> *)NULL, f);
a = GetTreeNode('A',b, c);
root = a;
break;
// nodes F, G, H, and I leaf nodes ; A is root node
case 2:
g = GetTreeNode('G');
h = GetTreeNode('H');
i = GetTreeNode('I');
d = GetTreeNode('D',(TreeNode<char> *)NULL, g);
e = GetTreeNode('E',h, i);
f = GetTreeNode('F');
b = GetTreeNode('B',d, (TreeNode<char> *)NULL);
c = GetTreeNode('C',e, f);
a = GetTreeNode('A',b, c);
root = a;
break;
// nodes F and C leaf nodes ; A is root node
case 3:
f = GetTreeNode('F');
d = GetTreeNode('D',f, (TreeNode<char> *)NULL);
c = GetTreeNode('C');
e = GetTreeNode('E',c, (TreeNode<char> *)NULL);
b = GetTreeNode('B',e,(TreeNode<char> *)NULL);
a = GetTreeNode('A',d,b);
root = a;
break;
// nodes C, D leaf nodes ; A is root node
case 4:
c = GetTreeNode('C');
b = GetTreeNode('B',(TreeNode<char> *)NULL,c);
d = GetTreeNode('D');
f = GetTreeNode('F',d,(TreeNode<char> *)NULL);
e = GetTreeNode('E',(TreeNode<char> *)NULL,f);
a = GetTreeNode('A',b,e);
root = a;
break;
}
}
void main(void)
{
// build two character trees
TreeNode<char> *root1, *root2;
// build character trees 3 and 4
MakeCharTree2(root1,3);
MakeCharTree2(root2,4);
// print each tree vertically
PrintVTree(root1, 1, 20);
cout << endl << endl << endl << endl;
PrintVTree(root2, 1, 20);
}
/*
<Run>
A
D B
F E
C
A
B E
C F
D
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -