📄 sorttree.cpp
字号:
// SortTree.cpp : Defines the entry point for the console application.
//
/*创建一棵二叉排序树,并采用中序遍历和层次遍历法输出其顶点序列
实验要点:
定义二叉排序树的结构BiTree;
编制二叉排序树的插入算法: void Insert_SortTree (BiTree ST, ElemType x);
编制中序遍历函数;
在main()函数中完成二叉排序树的建立,以及中序遍历的输出
二叉排序树的各个元素从键盘输入,并利用Insert_SortTree()函数进行插入建立
编制层次遍历函数,并在main()函数中完成层次遍历的输出。
需要定义一个队列结构(可以采用链队列,也可以采用循环顺序队列),并实现相关函数;
*/
#include "stdafx.h"
#include "BiTree.h"
#include "Queue.h"
#include "GlobalDefining.h"
#include <iostream.h>
extern void Insert_SortTree (BiTree &ST, int x);
extern void InOrderTraverse (BiTree ST);
extern void LevelTraverse (BiTree T);
extern STATUS InitQueue (SqQueue &Q);
extern STATUS EnQueue (SqQueue &Q, BiTNode *e);
extern STATUS DeQueue (SqQueue &Q, BiTNode *&e);
int main(int argc, char* argv[])
{
BiTree ST;
ST = NULL;
int x;
cout<<"输入一组数据,以-1结束,建立一棵排序二叉树T:"<<endl;
cin>>x;
while (x != -1)
{
Insert_SortTree (ST,x);
cin>>x;
}
cout<<endl;
cout<<"中序遍历输出为:";
InOrderTraverse (ST);
cout<<endl;
cout<<"层次遍历输出二叉树:";
LevelTraverse (ST);
cout<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -