
2005年华中科技大学计算机保研机试真题
代码:
#include <stdio.h>
#include <string.h>
struct Node{
Node *lchild;
Node *rchild;
int c;
}Tree[110];
int loc;
Node *creat(){
Tree[loc].lchild=Tree[loc].rchild=NULL;
return &Tree[loc++];
}
void postOrder(Node *T){
if(T->lchild!=NULL){
postOrder(T->lchild);
}
if(T->rchild!=NULL){
postOrder(T->rchild);
}
printf("%d ",T->c);
}
void inOrder(Node *T){
if(T->lchild!=NULL){
inOrder(T->lchild);
}
printf("%d ",T->c);
if(T->rchild!=NULL){
inOrder(T->rchild);
}
}
void preOrder(Node *T){
printf("%d ",T->c);
if(T->lchild!=NULL){
preOrder(T->lchild);
}
if(T->rchild!=NULL){
preOrder(T->rchild);
}
}
Node *Insert(Node *T ,int x){
if(T==NULL){
T=creat();
T->c=x;
}
else if(x<T->c){
T->lchild=Insert(T->lchild,x);
}else if(x>T->c){
T->rchild=Insert(T->rchild,x);
}
return T;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
loc=0;
Node *T=NULL;
int i;
for(i=0;i<n;i++){
int x;
scanf("%d",&x);
T=Insert(T,x);
}
preOrder(T);
printf("\n");
inOrder(T);
printf("\n");
postOrder(T);
printf("\n");
}
return 0;
}
题目1009:二叉搜索树

时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:7978

解决:3522
题目描述:
判断两序列是否为同一二叉搜索树序列
输入:

开始一个数n,(1<=n<=20) 表示有n个必须判定,n= 0 的之后输入结束。
接下去一行是一个序列,序列长度大于10,包含(0~9)的数字,没有重复数字二叉排序树 构造二叉排序树 构造,根据这个序列可以构造出一颗二叉搜索树。
接下去的n行有n个序列,每个序列格式和第一个序列一样,请判断这两个序列是否可构成同一颗二叉搜索树。
输出:

如果序列相同则输出YES,否则输出NO
样例输入:
2 567432 543267 576342 0
样例输出:
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-141302-1.html
四
房价不降
3亿人
Itunes升比较稳定
羞辱中国