
我试写了下二叉树的构建,插入,排序问题,大家帮我说说哪里不对#include<stdio.h>#include<stdlib.h>#include<stdbool.h>#definestatusboolintmain(){//|==========================...我试写了下二叉树的构建,插入创建二叉排序树,排序问题,大家帮我说说那儿不对
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
#define status bool
int main()
{
//|=================================
//| Define BiTNode struct
//|=================================
typedef struct BiTNode
{

int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
//|=================================
//|Function:Insert a value to Bi Tree
//|=================================
status InsertBST(BiTree *T,int key)
{
BiTree p,s;
if(!SearchBST(*T,key,NULL,&p))
{
s = (BiTree)malloc(sizeof(BiTNode));

s->data = key;
s->lchild = NULL;
s->rchild=NULL;
if(!p)
*T = s;
else if(key<p->data)
p->lchild =s;
else
p->rchild =s;
return true;
}
else

return false;
}
int i;
int test[]={62,88,58,47,35,73,51,99,37,93};
BiTree T = NULL;
for(i=0;i<10;i++)
InsertBST(&T,test[i]);
printf("Before sort\n");
for (i=0;i<10;i++)
printf("%d ",test[i]);
printf("\n");
printf("After Bi Tree sorted\n");

InOrderTraverse(BiTree t)
{
if(t == NULL)
return;
InOrderTraverse(t->lchild);
printf("%d ",t->data);
InOrderTraverse(tr->rchild);
}
InOrderTraverse(T);
system("pause");
return 0;
}
系统报错创建二叉排序树,但没提醒哪里错~
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-123766-1.html
OMG~~rocker