2 baidu 24427837 baidu_24427837 于 2014.12.11 18:40 提问

这个程序麻烦各位大神帮忙看下错在哪里了,谢谢
c++

#include
#include
#include
typedef int ElemType;
typedef struct Student
{
int num;
char name[20];
char birthday[20];
char tel[20];
}Student;
typedef struct BiTNode
{
struct Student stu;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
int SearchBST(BiTree T,int num,BiTree f,BiTree *p,char name[])
{
if(!T)
{
*p = f;
return 0;
}
else
{
if(!strcmp(name,T->stu.name))
{
*p = T;
return 1;
}
else
{
if(num < T->stu.num)
{
return SearchBST(T->lchild,num,T,p,name);
}
else
{
return SearchBST(T->rchild,num,T,p,name);
}
}
}
}
void ProOrderTraverse(BiTree T)
{
if(T==NULL)
{
return;
}
else
{
printf("name: ");
printf("num: ");
printf("birthday ");
printf("tel ");
printf("\n");
printf("%-10s",T->stu.name);
printf("%-10d",T->stu.num);
printf("%-10s",T->stu.birthday);
printf("%-10s",T->stu.tel);
printf("\n");
ProOrderTraverse(T->lchild);
ProOrderTraverse(T->rchild);
}
}
int InsertBST(BiTree *T,int num,char name[],char birthday[],char tel[])
{
BiTree p,s;
if(!SearchBST(*T,num,NULL,&p,name))
{
s = (BiTree)malloc(sizeof(BiTNode));
s->stu.num= num;
strcpy(s->stu.name,name);
strcpy(s->stu.birthday,birthday);
strcpy(s->stu.tel,tel);
s->lchild = s->rchild =NULL;
if(!p)
{
*T = s;
}
else
{
if(num<(p->stu.num))
{
p->lchild = s;
}
else
{
p->rchild = s;
}
}
return 1;
}
else
{
return 0;
}
}
void InsertStudent(BiTree *T)
{
int num;
char name[20];
char birthday[20];
char tel[20];
printf("Insert name:\n");
scanf(" %s",&name);
printf("Insert num:\n");
scanf(" %d",&num);
printf("Insert birthday:\n");
scanf(" %s",&birthday);
printf("Insert tel:\n");
scanf(" %s",&tel);
InsertBST(T,num,name,birthday,tel);
}
int Delete(BiTree *T,char name[10])
{
if(!*T)
{
return 0;
}
else
{
if(!strcmp(name,(*T)->stu.name))
{
return Delete(*T);
}
else
{
return Delete(&(*T)->lchild,name);
return Delete(&(*T)->rchild,name);
}
}
}
int Delete(BiTree *p)
{
BiTree q,s;
if((*p)->rchild == NULL)
{
q = *p;
*p = (*p)->lchild;
free(q);
}
else
{
if((*p)->lchild == NULL)
{
q = *p;
*p = (*p)->rchild;
free(q);
}
else
{
q=*p;
s=(*p)->lchild;
while(s->rchild)
{
q = s;
s = s->rchild;
}
(*p)->stu.num=s->stu.num;
strcpy((*p)->stu.name,s->stu.name);
strcpy((*p)->stu.birthday,s->stu.birthday);
strcpy((*p)->stu.tel,s->stu.tel);
if(q != *p)
{
q->rchild = s->lchild;
}
else
{
q->lchild = s->lchild;
}
free(s);
}
}
return 1;
}
void DeleteStudent(BiTree *T)
{
char name[20];
printf("Delete the name:\n");
scanf(" %s",&name);
Delete(T,name);
}
int Alter(BiTree *T,char name[10])
{
if(!*T)
{
return 0;
}
else
{
if(!strcmp(name,(*T)->stu.name))
{
return Alter(*T);
}
else
{
return Alter(&(*T)->lchild,name);
return Alter(&(*T)->rchild,name);
}
}
}
int Alter(BiTree *p)
{
int num;
char name[20];
char birthday[20];
char tel[20];
printf("name: ");
printf("num: ");
printf("birthday ");
printf("tel ");
printf("\n");
printf("%-10s",(*p)->stu.name);
printf("%-10d",(*p)->stu.num);
printf("%-10s",(*p)->stu.birthday);
printf("%-10s",(*p)->stu.tel);
printf("\n");
printf("Alter the name to:\n");
scanf(" %s",&name);
printf("Alter the num to:\n");
scanf(" %d",&num);
printf("Alter the birthday to:\n");
scanf(" %s",&birthday);
printf("Alter the tel to:\n");
scanf(" %s",&tel);
(*p)->stu.num=num;
strcpy((*p)->stu.name,name);
strcpy((*p)->stu.birthday,birthday);
strcpy((*p)->stu.tel,tel);
return 1;
}
void AlterStudent(BiTree *T)
{
char name[20];
printf("Alter the name:\n");
scanf(" %s",&name);
Alter(T,name);
}
int main()
{
int i;
BiTree T=NULL;
while(1)
{
printf("1.Show student\n");
printf("2.Insert student\n");
printf("3.Delete student\n");
printf("4.Alter student\n");
do
{
scanf(" %d",&i);
}
while(i!=1&&i!=2&&i!=3&&i!=4);
system("clear");
switch(i)
{
case 1:
{
ProOrderTraverse(T);
break;
}
case 2:
{
ProOrderTraverse(T);
InsertStudent(&T);
break;
}
case 3:
{
ProOrderTraverse(T);
DeleteStudent(&T);
ProOrderTraverse(T);
break;
}
case 4:
{
ProOrderTraverse(T);
AlterStudent(&T);
break;
}
default:
{
break;
}
}
}
return 0;
}

6个回答

happyparrot
happyparrot   Ds   Rxr 2014.12.12 12:54

不是我疯了,那一定就是你疯了.

lx624909677
lx624909677   Ds   Rxr 2014.12.12 13:40

调试程序,如果程序蹦了,点重试,看看断在哪一行,看看内存中变量的数据是否正常

Learning__exe
Learning__exe   2014.12.14 13:57

程序还没看 不知道你include的是什么

Learning__exe
Learning__exe   2014.12.14 13:57

程序还没看 不知道你include的是什么

baidu_24427837
baidu_24427837 为什么?
大约 3 年之前 回复
Learning__exe
Learning__exe   2014.12.14 13:57

程序还没看 不知道你include的是什么

baidu_24427837
baidu_24427837 <stdio.h>
大约 3 年之前 回复
Learning__exe
Learning__exe   2014.12.14 13:57

程序还没看 不知道你include的是什么

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!