?? 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 + -