文章
9
粉丝
126
获赞
11
访问
52.0k
新手
#include <iostream>
using namespace std;
#include <string.h>
typedef struct node //结构体
{
int data;
struct node *lchild, *rchild;
}*BSTree;
int i = 0;//全局变量
int j = 0;
void InsertBSTree (BSTree &T, int x)//建立BST
{
if ( T == NULL)
{
T = new node;
T->data = x;
T->lchild = NULL;
T->rchild = NULL;
return;
}
if (x == T->data ) return;
else if (x > T->data ) InsertBSTree (T->rchild , x);
else InsertBSTree (T->lchild , x);
}
void PreOrderTraverse (BSTree T, int *Pre)//先序遍历
{
if (T != NULL)
{
Pre[i++] = T->data ;
PreOrderTraverse (T->lchild , Pre);
PreOrderTraverse (T->rchild , Pre);
}
}
void InOrderTraverse (BSTree T, int *In)//中序遍历
{
if (T != NULL)
{
InOrderTraverse (T->lchild , In);
In[j++] = T->data ;
InOrderTraverse (T->rchild , In);
}
}
int main ()
{
char s[10];
int n;
while (cin >> n)
{
int Pre[10*n];//所有...
登录后发布评论
暂无评论,来抢沙发