#include"stdio.h"
#include"stdlib.h"
#define NULL 0
#define maxsize 50
typedef struct node{
char data;
struct node *lchild,*rchild;
}Bitree;
int a[maxsize];
int temp=0;
Bitree *Q[maxsize];
Bitree *Creatree(){
char ch;
int front,rear;
Bitree *T,*S;
T=NULL;
front=1;rear=0;
printf("建立二叉树,以@表示虚节点,以#结束输入:\n");
ch=getchar();
while(ch!='#'){
S=NULL;
if(ch!='@'){ //@表示虚节点不是虚节点是建立新节点
S=(Bitree *)malloc(sizeof(Bitree));
S->data=ch;
S->lchild=S->rchild=NULL;
}
rear++;Q[rear]=S; //将虚节点指针NULL或新节点地址入队
if(rear==1)
T=S; //输入第一个节点为根节点
else{
if(S!=NULL&&Q[front]!=NULL)
if(rear%2==0)
Q[front]->lchild=S;
else Q[front]->rchild=S;
if(rear%2==1) front++; //节点Q[front]的两个孩子已经处理完毕,front+1
}
ch=getchar();
}
return T;
}
void Inorder(Bitree *T){ //中序遍历二叉树,并将每个结点数据存入数组中if(T!=NULL){
Inorder(T->lchild);
printf("%d\t",T->data);
Inorder(T->rchild);
a[temp]=T->data;
temp++;
}
}
int Judge_bitree(int a[]){ //判断是否是二叉树int i,flag=1;
for(i=0;i<temp-1;i++){
if(a[i]>a[i+1]){
flag=0;
break;
}
}
return flag;
}
void main(){
int b=Judge_bitree(a);
Bitree *T;
T=Creatree();
if(b==1)
printf("给定二叉树是二叉排序树!\n");
if(b==0)
printf("给定二叉树不是二叉排序树!\n"); }。