一个学生成绩的管理程序,运行不了,能帮忙找下错误吗
#include<stdio.h>
#include<stdlib.h>
#include<string>
#define max 100
typedef struct Stu{
int number;
char name;
struct Stu *next;
}Stu,*linklist;
typedef struct TStudentMark{
int mark;
int count;
struct TStudentMark *lchild,*rchild;
Stu *list;
}TStudentMark,*TSMark;
void mainlist(TSMark tree);
TSMark insert(TSMark tree,int score,int num,char nam)
{
TSMark p,q,t;
linklist l,i,j;
p=tree;
q=NULL;
while(p&&p->mark!=score)
{
p=q;
if(score<p->mark)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL)
{
t=(TSMark)malloc(sizeof(TStudentMark));
t->mark=score;
t->lchild=t->rchild=NULL;
l=t->list;
l=(linklist)malloc(sizeof(Stu));
l->number=num;
l->name=nam;
l->next=NULL;
if(tree==NULL)tree=t;
else if(q->mark>score)q->lchild=t;
else q->rchild=t;
}
if(p->mark==score)
{
while(i)
{
j=i;
i=i->next;
}
i=j->next;
i->number=num;
i->name=nam;
i->next=NULL;
}
return tree;
}
void Fun_1(TSMark tree)
{int score,num;
char nam;
printf("请输入成绩、学号,姓名:\n");
scanf("%d %d %c",&score,&num,&nam);
tree=insert(tree,score,num,nam);
printf("输入完毕,继续请按1,其他退出;");
int k;
scanf("%d",&k);
if(k==1)Fun_1(tree);
else {system("cls");mainlist(tree);}
}
void Fun_2(TSMark tree)
{TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p||top)
{
while(p)
{
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
printf("分数:%2d\n",p->mark);
printf("学号、姓名:");
l=p->list;
while(l)
{
printf("%d %c ",l->number,l->name);
l=l->next;
}
}
p=p->rchild;
}
void Fun_3(TSMark tree)
{
TSMark p,s[max];
linklist l;
int num,top=0;
p=tree;
printf("请输入学号:");
scanf("%3d",&num);
while(p||top)
{
while(P)
{
l=p->list;
if(l->number!=num)
{
l=l->next;
}
printf("该生成绩为:%2d",p->mark);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
p=p->rchild;
}
}
}
void Fun_4(TSMark tree)
{
TSMark p;
linklist l;
int top=0;
p=tree;
while(p||top)
{
while(p)
{
l=p->list;
p->count=0;
if(l)
{
p->count++;l=l->next;
}
printf("分数:%2d 人数:%2d\n",p->mark,p->count);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[top--];
p=p->rchild;
}
}
if(tree==NULL)
{
printf("还未录入成绩,请稍后查询。\n");
printf("返回请按1.");
int k;
scanf("%d",&k);
if(k==1){system("cls");mainlist(tree);}
}
}
void delet_L(linklist head,int num)
{
linklist l,p;
l=head;
while(l->number==num)
{
p=l;l=l->next;free(p);
}
}
TSMark delet_T(TSMark tree,int num,int score)
{
TSMark p,parent,s,q; //parent指向要删除的节点的双亲,p指向要删除的节点
p=tree;
parent=NULL;
while(p)
{
if(p->mark==score)
break;
parent=p;
if(p->mark>score)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL) //不存在该树节点
return tree;
if(p->lchild==NULL) //无左子树,右子树可有可无
{
if(parent==NULL)
tree=p->rchild;
else
if(parent->lchild==p)
parent->lchild=p->rchild;
else
parent->rchild=p->rchild;
delet_L (p->list,num); free(p);
}
else //有左子树,右子树可有可无
{
q=p;
s=q->lchild; ////
while(s->rchild)
{
q=s;
s=s->rchild;
}
if(q==p) //其左孩子没有右子树
q->lchild=s->lchild;
else
q->rchild=s->lchild;
p->score=s->score; delet_L (s->list,num);
free(s);
}
return tree;
}
void Fun_5(TSMark tree)
{
int num,score;
TSMark p;
p=tree;
printf("输入要删除的分数:%3d\n");
scanf("%d",&score);
printf("输入要删除的学号:%3d\n");
scanf("%d",&num);
delet_T(tree,num,score);
}
void mainlist(TSMark tree)
{system("cls");
printf("**********欢迎使用上海理工大学学生成绩管理系统**********\n");
printf(" 请选择: \n");
printf(" 1、学生成绩、信息输入 \n");
printf(" 2、升序浏览 \n");
printf(" 3、成绩查询 \n");
printf(" 4、统计 \n");
printf(" 5、删除 \n");
printf(" 6、退出 \n");
printf("********************************************************\n");
int n;
scanf("%d",&n);
switch(n)
{
case 1:Fun_1(tree);
break;
case 2:Fun_2(tree)
break;
case 3:Fun_3(tree);
break;
case 4:Fun_4(tree);
break;
case 5:Fun_5(tree);
break;
case 6:exit;
default :printf("输入错误,请重新选择");
}
system("pause");
}
void main()
{
TSMark tree=NULL;
mainlist(tree);
}
[解决办法]
也就是我下午闲着没事,给你找找错,遇到这样的问题楼主还是要自己动手去找找错误吧
#include<stdio.h>
#include<stdlib.h>
#include<string>
#define max 100
typedef struct Stu{
int number;
char name;
struct Stu *next;
}Stu,*linklist;
typedef struct TStudentMark{
int mark;
int count;
struct TStudentMark *lchild,*rchild;
Stu *list;
}TStudentMark,*TSMark;
void mainlist(TSMark tree);
TSMark insert(TSMark tree,int score,int num,char nam)
{
TSMark p,q,t;
linklist l,i,j;
p=tree;
q=NULL;
while(p&&p->mark!=score)
{
p=q;
if(score<p->mark)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL)
{
t=(TSMark)malloc(sizeof(TStudentMark));
t->mark=score;
t->lchild=t->rchild=NULL;
l=t->list;
l=(linklist)malloc(sizeof(Stu));
l->number=num;
l->name=nam;
l->next=NULL;
if(tree==NULL)tree=t;
else if(q->mark>score)q->lchild=t;
else q->rchild=t;
}
if(p->mark==score)
{
while(i)
{
j=i;
i=i->next;
}
i=j->next;
i->number=num;
i->name=nam;
i->next=NULL;
}
return tree;
}
void Fun_1(TSMark tree)
{
int score,num;
char nam;
printf("请输入成绩、学号,姓名:\n");
scanf("%d %d %c",&score,&num,&nam);
tree=insert(tree,score,num,nam);
printf("输入完毕,继续请按1,其他退出;");
int k;
scanf("%d",&k);
if(k==1)
Fun_1(tree);
else
{
system("cls");
mainlist(tree);
}
}
void Fun_2(TSMark tree)
{
TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
printf("分数:%2d\n",p->mark);
printf("学号、姓名:");
l=p->list;
while(l)
{
printf("%d %c ",l->number,l->name);
l=l->next;
}
}
p=p->rchild;
}
}
void Fun_3(TSMark tree)
{
TSMark p,s[max];
linklist l;
int num,top=0;
p=tree;
printf("请输入学号:");
scanf("%3d",&num);
while(p
[解决办法]
top)
{
while(p)
{
l=p->list;
if(l->number!=num)
{
l=l->next;
}
printf("该生成绩为:%2d",p->mark);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
p=p->rchild;
}
}
}
void Fun_4(TSMark tree)
{
TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
l=p->list;
p->count=0;
if(l)
{
p->count++;l=l->next;
}
printf("分数:%2d 人数:%2d\n",p->mark,p->count);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[top--];
p=p->rchild;
}
}
if(tree==NULL)
{
printf("还未录入成绩,请稍后查询。\n");
printf("返回请按1.");
int k;
scanf("%d",&k);
if(k==1){system("cls");mainlist(tree);}
}
}
void delet_L(linklist head,int num)
{
linklist l,p;
l=head;
while(l->number==num)
{
p=l;
l=l->next;
free(p);
}
}
TSMark delet_T(TSMark tree,int num,int score)
{
TSMark p,parent,s,q; //parent指向要删除的节点的双亲,p指向要删除的节点
p=tree;
parent=NULL;
while(p)
{
if(p->mark==score)
break;
parent=p;
if(p->mark>score)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL) //不存在该树节点
return tree;
if(p->lchild==NULL) //无左子树,右子树可有可无
{
if(parent==NULL)
tree=p->rchild;
else
if(parent->lchild==p)
parent->lchild=p->rchild;
else
parent->rchild=p->rchild;
delet_L (p->list,num); free(p);
}
else //有左子树,右子树可有可无
{
q=p;
s=q->lchild; ////
while(s->rchild)
{
q=s;
s=s->rchild;
}
if(q==p) //其左孩子没有右子树
q->lchild=s->lchild;
else
q->rchild=s->lchild;
p->mark = s->mark;
delet_L (s->list,num);
free(s);
}
return tree;
}
void Fun_5(TSMark tree)
{
int num,score;
TSMark p;
p=tree;
printf("输入要删除的分数:%3d\n");
scanf("%d",&score);
printf("输入要删除的学号:%3d\n");
scanf("%d",&num);
delet_T(tree,num,score);
}
void mainlist(TSMark tree)
{system("cls");
printf("**********欢迎使用上海理工大学学生成绩管理系统**********\n");
printf(" 请选择: \n");
printf(" 1、学生成绩、信息输入 \n");
printf(" 2、升序浏览 \n");
printf(" 3、成绩查询 \n");
printf(" 4、统计 \n");
printf(" 5、删除 \n");
printf(" 6、退出 \n");
printf("********************************************************\n");
int n;
scanf("%d",&n);
switch(n)
{
case 1:Fun_1(tree);
break;
case 2:Fun_2(tree);
break;
case 3:Fun_3(tree);
break;
case 4:Fun_4(tree);
break;
case 5:Fun_5(tree);
break;
case 6:exit;
default :printf("输入错误,请重新选择");
}
system("pause");
}
void main()
{
TSMark tree=NULL;
mainlist(tree);
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max 100
typedef struct Stu
{
int number;
char name;
struct Stu *next;
}Stu, *linklist;
typedef struct TStudentMark
{
int mark;
int count;
struct TStudentMark *lchild,*rchild;
Stu *list;
}TStudentMark,*TSMark;
void mainlist(TSMark tree);
TSMark insert(TSMark tree,int score,int num,char nam)
{
TSMark p,q,t;
linklist l,i,j;
p=tree;
q=NULL;
while(p&&p->mark != score)
{
p = q;
if(score<p->mark)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL)
{
t=(TSMark)malloc(sizeof(TStudentMark));
t->mark=score;
t->lchild=t->rchild=NULL;
l=t->list;
l=(linklist)malloc(sizeof(Stu));
l->number=num;
l->name=nam;
l->next=NULL;
if(tree==NULL)tree=t;
else if(q->mark>score)q->lchild=t;
else q->rchild=t;
}
if(p->mark==score)
{
while(i)
{
j=i;
i=i->next;
}
i=j->next;
i->number=num;
i->name=nam;
i->next=NULL;
}
return tree;
}
void Fun_1(TSMark tree)
{int score,num;
char nam;
printf("请输入成绩、学号,姓名:\n");
scanf("%d %d %c",&score,&num,&nam);
tree=insert(tree,score,num,nam);
printf("输入完毕,继续请按1,其他退出;");
int k;
scanf("%d",&k);
if(k==1)Fun_1(tree);
else {system("cls");mainlist(tree);}
}
void Fun_2(TSMark tree)
{
TSMark p,s[max];
linklist l;
int top = 0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
s[top++]=p;
p=p->lchild;
}
if(top)
{
p = s[--top];
printf("分数:%2d\n",p->mark);
printf("学号、姓名:");
l=p->list;
while(l)
{
printf("%d %c ",l->number,l->name);
l=l->next;
}
}
p = p->rchild;
}
}
void Fun_3(TSMark tree)
{
TSMark p, s[max];
linklist l;
int num,top=0;
p=tree;
printf("请输入学号:");
scanf("%3d",&num);
while(p
[解决办法]
top)
{
while(p) //这儿p大写了
{
l = p->list;
if(l->number != num)
{
l = l->next;
}
printf("该生成绩为:%2d",p->mark);
s[top++] = p;
p = p->lchild;
}
if(top)
{
p = s[--top];
p = p->rchild;
}
}
}
void Fun_4(TSMark tree)
{
TSMark p, s[max];
linklist l;
int top = 0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
l = p->list;
p->count=0;
if(l)
{
p->count++;l=l->next;
}
printf("分数:%2d 人数:%2d\n",p->mark,p->count);
s[top++] = p; //未定义的s
p = p->lchild;
}
if(top)
{
p = s[top--];
p = p->rchild;
}
}
if(tree==NULL)
{
printf("还未录入成绩,请稍后查询。\n");
printf("返回请按1.");
int k;
scanf("%d",&k);
if(k==1)
{
system("cls");
mainlist(tree);
}
}
}
void delet_L(linklist head,int num)
{
linklist l,p;
l=head;
while(l->number==num)
{
p=l;l=l->next;free(p);
}
}
TSMark delet_T(TSMark tree,int num,int score)
{
TSMark p, parent, s, q; //parent指向要删除的节点的双亲,p指向要删除的节点
p = tree;
parent = NULL;
while(p)
{
if(p->mark==score)
break;
parent=p;
if(p->mark>score)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL) //不存在该树节点
return tree;
if(p->lchild == NULL) //无左子树,右子树可有可无
{
if(parent == NULL)
tree=p->rchild;
else
if(parent->lchild == p)
parent->lchild = p->rchild;
else
parent->rchild = p->rchild;
delet_L (p->list,num);
free(p);
}
else //有左子树,右子树可有可无
{
q=p;
s=q->lchild; ////
while(s->rchild)
{
q=s;
s=s->rchild;
}
if(q == p) //其左孩子没有右子树
{
q->lchild=s->lchild;
}
else
{
q->rchild = s->lchild;
}
p->mark = s->mark; //这儿应该是mark吧
delet_L (s->list, num);
free(s);
}
return tree;
}
void Fun_5(TSMark tree)
{
int num,score;
TSMark p;
p = tree;
printf("输入要删除的分数:");
scanf("%d",&score);
printf("输入要删除的学号: "); //这儿应该去掉%3d
scanf("%d",&num);
delet_T(tree, num, score);
}
void mainlist(TSMark tree)
{
system("cls");
printf("**********欢迎使用上海理工大学学生成绩管理系统**********\n");
printf(" 请选择: \n");
printf(" 1、学生成绩、信息输入 \n");
printf(" 2、升序浏览 \n");
printf(" 3、成绩查询 \n");
printf(" 4、统计 \n");
printf(" 5、删除 \n");
printf(" 6、退出 \n");
printf("********************************************************\n");
int n;
scanf("%d",&n);
switch(n)
{
case 1:Fun_1(tree);
break;
case 2:Fun_2(tree); //这儿少个分号";"
break;
case 3:Fun_3(tree);
break;
case 4:Fun_4(tree);
break;
case 5:Fun_5(tree);
break;
case 6: exit(0);
break;
default :
printf("输入错误,请重新选择");
break;
}
system("pause");
}
int main(void)
{
TSMark tree = NULL;
mainlist(tree);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max 100
typedef struct Stu
{
int number;
char name;
struct Stu *next;
} Stu,*linklist;
typedef struct TStudentMark
{
int mark;
int count;
struct TStudentMark *lchild,*rchild;
Stu *list;
} TStudentMark,*TSMark;
void mainlist(TSMark tree);
TSMark insert(TSMark tree,int score,int num,char nam)
{
TSMark p,q,t;
linklist l,i,j;
p=tree;
q=NULL;
while(p&&p->mark!=score)
{
p=q;
if(score<p->mark)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL)
{
t=(TSMark)malloc(sizeof(TStudentMark));
t->mark=score;
t->lchild=t->rchild=NULL;
l=t->list;
l=(linklist)malloc(sizeof(Stu));
l->number=num;
l->name=nam;
l->next=NULL;
if(tree==NULL)tree=t;
else if(q->mark>score)q->lchild=t;
else q->rchild=t;
}
if(p->mark==score)
{
while(i)
{
j=i;
i=i->next;
}
i=j->next;
i->number=num;
i->name=nam;
i->next=NULL;
}
return tree;
}
void Fun_1(TSMark tree)
{
int score,num;
char nam;
printf("请输入成绩、学号,姓名:\n");
scanf("%d %d %c",&score,&num,&nam);
tree=insert(tree,score,num,nam);
printf("输入完毕,继续请按1,其他退出;");
int k;
scanf("%d",&k);
if(k==1)
Fun_1(tree);
else
{
system("cls");
mainlist(tree);
}
}
void Fun_2(TSMark tree)
{
TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
printf("分数:%2d\n",p->mark);
printf("学号、姓名:");
l=p->list;
while(l)
{
printf("%d %c ",l->number,l->name);
l=l->next;
}
}
p=p->rchild;
}
}
void Fun_3(TSMark tree)
{
TSMark p,s[max];
linklist l;
int num,top=0;
p=tree;
printf("请输入学号:");
scanf("%3d",&num);
while(p
[解决办法]
top)
{
while(p)
{
l=p->list;
if(l->number!=num)
{
l=l->next;
}
printf("该生成绩为:%2d",p->mark);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[--top];
p=p->rchild;
}
}
}
void Fun_4(TSMark tree)
{
TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p
[解决办法]
top)
{
while(p)
{
l=p->list;
p->count=0;
if(l)
{
p->count++;
l=l->next;
}
printf("分数:%2d 人数:%2d\n",p->mark,p->count);
s[top++]=p;
p=p->lchild;
}
if(top)
{
p=s[top--];
p=p->rchild;
}
}
if(tree==NULL)
{
printf("还未录入成绩,请稍后查询。\n");
printf("返回请按1.");
int k;
scanf("%d",&k);
if(k==1)
{
system("cls");
mainlist(tree);
}
}
}
void delet_L(linklist head,int num)
{
linklist l,p;
l=head;
while(l->number==num)
{
p=l;
l=l->next;
free(p);
}
}
TSMark delet_T(TSMark tree,int num,int score)
{
TSMark p,parent,s,q; //parent指向要删除的节点的双亲,p指向要删除的节点
p=tree;
parent=NULL;
while(p)
{
if(p->mark==score)
break;
parent=p;
if(p->mark>score)
p=p->lchild;
else
p=p->rchild;
}
if(p==NULL) //不存在该树节点
return tree;
if(p->lchild==NULL) //无左子树,右子树可有可无
{
if(parent==NULL)
tree=p->rchild;
else if(parent->lchild==p)
parent->lchild=p->rchild;
else
parent->rchild=p->rchild;
delet_L (p->list,num);
free(p);
}
else //有左子树,右子树可有可无
{
q=p;
s=q->lchild; ////
while(s->rchild)
{
q=s;
s=s->rchild;
}
if(q==p) //其左孩子没有右子树
q->lchild=s->lchild;
else
q->rchild=s->lchild;
p->mark = s->mark;
delet_L (s->list,num);
free(s);
}
return tree;
}
void Fun_5(TSMark tree)
{
int num,score;
TSMark p;
p=tree;
printf("输入要删除的分数:%3d\n");
scanf("%d",&score);
printf("输入要删除的学号:%3d\n");
scanf("%d",&num);
delet_T(tree,num,score);
}
void mainlist(TSMark tree)
{
system("cls");
printf("**********欢迎使用上海理工大学学生成绩管理系统**********\n");
printf(" 请选择: \n");
printf(" 1、学生成绩、信息输入 \n");
printf(" 2、升序浏览 \n");
printf(" 3、成绩查询 \n");
printf(" 4、统计 \n");
printf(" 5、删除 \n");
printf(" 6、退出 \n");
printf("********************************************************\n");
int n;
scanf("%d",&n);
switch(n)
{
case 1:
Fun_1(tree);
break;
case 2:
Fun_2(tree);
break;
case 3:
Fun_3(tree);
break;
case 4:
Fun_4(tree);
break;
case 5:
Fun_5(tree);
break;
case 6:
exit;
default :
printf("输入错误,请重新选择");
}
system("pause");
}
void main()
{
TSMark tree=NULL;
mainlist(tree);
}