exam7-1.cpp
来自「数据结构c++-书的一些源代码」· C++ 代码 · 共 50 行
CPP
50 行
#include <iostream.h>
#include "BiTreeNode.h"
#include "BiTreeTraverse.h"
void MakeCharTree(BiTreeNode<char>* &root)
{
BiTreeNode<char> *b, *c, *d, *e, *f, *g, *null = NULL;
g = GetTreeNode('G');
d = GetTreeNode('D', null, g);
b = GetTreeNode('B', d);
e = GetTreeNode('E');
f = GetTreeNode('F');
c = GetTreeNode('C', e, f);
root = GetTreeNode('A', b, c);
}
void Printchar(char item)
{
cout << item << " ";
}
void main(void)
{
BiTreeNode<char> *root1, *p;
MakeCharTree(root1);
cout << "二叉树为:" << endl;
PrintBiTree(root1, 0);
cout << "\n前序遍历结点次序为: ";
PreOrder(root1, Printchar);
cout << "\n中序遍历结点次序为: ";
InOrder(root1, Printchar);
cout << "\n后序遍历结点次序为: ";
PostOrder(root1, Printchar);
p = Search(root1, 'C');
if(p != NULL)
cout << "\n查找到的结点数据值为:" << p->data;
else
cout << "\n查找失败";
cout << "\n撤消结点次序为: ";
Destroy(root1);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?