二叉树的程序,运行不了,求各位大侠帮帮忙。。。

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:49:02
用二叉排序树做的简单的学生信息查询,但结果不对。。。烦
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int Keytype;
typedef struct node
{ Keytype score;//成绩设为关键字
char name[10];//学生成绩
char xuenum[12];//学号
struct node *lchild,*rchild;
}Stunode;
typedef Stunode * Stutree;
inserttree(Stutree *T,Stunode *S)//插入树的结点
{Stunode *p,*f=*T;
while(!p){
f=p;
p=((S->score)<=(p->score))?p->lchild:p->rchild;
}
p=(Stunode *)malloc(sizeof(Stunode));
strcpy(p->name,S->name);
strcpy(p->xuenum,S->xuenum);
p->score=S->score;
p->lchild=NULL;
p->rchild=NULL;
if(*T==NULL)*T=p;
else
if(S->score<=f->score)f->lchild=p;
else f->rchild=p;
}
Stutree creatree()//建立二叉排序树
{ Stutree T=NULL;
Stunode *Stuinfo;
char flag;
flag='y';
printf("输入学生信息:\n

插入函数不对。。。我改了,你试试
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h> //调用getch();
typedef long int Keytype;
typedef struct node
{
int score;//
char name[20];//学生成绩
Keytype xuenum;//学号设为关键字
struct node *lchild,*rchild;
}Stunode;
typedef Stunode *Stutree;
void inserttree(Stutree *root,Stunode *Stuinfo) //插入结点
{
if(*root == NULL)
{
*root = Stuinfo;
}
else if((*root)->xuenum >= Stuinfo->xuenum)//学号小的放在左边;
inserttree(&(*root)->lchild,Stuinfo);
else
inserttree(&(*root)->rchild,Stuinfo);
}
Stutree creatree()//建立二叉排序树
{
Stutree T=NULL;
Stunode *Stuinfo;
char flag;
printf("输入学生信息:\n");
while(1)
{
printf("学生姓名 学号 学习成绩\n")