我的程序怎么运行不了

it巨匠 2012-11-21 09:56:42
# include "stdio.h"
# include "stdlib.h"
# define FALSE 0
# define TRUE 1
# define n 4
typedef int datatype;
typedef struct
{ int key;
datatype other;
}rectype;
struct student
{ long num;
char name[20];
char sex;
int age ;
char major[10];
int score;
}d[4];
void enter() /*输入学生信息*/
{ int i;
for(i=1;i<n;i++)
{
printf("next enter the student%d's information\n",i+1);
printf("please enter the number of the student:\n");
scanf("%ld",&d[i].num);
printf("please enter the student's name :\n");
scanf("%s",d[i].name) ; getchar();
printf("please enter the sex of the student:\n");
d[i].sex=getchar(); getchar();
printf("please enter the age of the student:\n");
scanf("%d",&d[i].age);
printf("please enter the major of the student:\n ");
scanf("%s",d[i].major);
printf("please enter score of the student:\n");
scanf("%d",&d[i].score);
}
}
void output()
{ int i;
for(i=1;i<4;i++)
{ printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
}
void INSERTSORT()
{ int i,j;rectype R[n];
enter();
for(i=1;i<4;i++)
R[i].key=d[i].score;
for(i=2;i<n;i++)
{ R[0]=R[i];
j=i-1;
while(R[0].key<R[j].key)
R[j+1]=R[j--];
R[j+1]=R[0];
}
for(i=1;i<n;i++)
{
d[i].score=R[i].key;
printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
}
void BUBBLESORT()
{ int i,j,noswap;
rectype temp;
rectype R[n];
enter();
for(i=1;i<4;i++)
R[i].key=d[i].score;
for(i=1;i<n-1;i++)
{ noswap=TRUE;
for(j=n-2;j>=i;j--)
if(R[j+1].key<R[j].key)
{ temp=R[j+1];
R[j+1]=R[j];
R[j]=temp;
noswap=FALSE;
}
if(noswap)
break;
}
for(i=1;i<n;i++)
{
d[i].score=R[i].key;
printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
}
void SELECTSORT()
{ int i,j,k;
rectype temp;
rectype R[n];
enter();
for(i=1;i<4;i++)
R[i].key=d[i].score;
for(i=1;i<n-1;i++)
{ k=i;
for(j=i+1;j<n;j++)
if(R[j].key<R[k].key)
k=j;
if(k!=i)
{ temp=R[i];
R[i]=R[k];
R[k]=temp;
}
}
for(i=1;i<n;i++)
{
d[i].score=R[i].key;
printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
}
int PARTITION(rectype R[n],int l,int h)
{ int i,j;
rectype temp;
i=l;j=h;temp=R[i];
do{
while((R[j].key>=temp.key)&&(i<j))
j--;
if(i<j) R[i++]=R[j];
while((R[j].key<=temp.key)&&(i<j))
i++;
if(i<j) R[j--]=R[i];
} while(i!=j);
R[i]=temp;
return i;
}
QUICKSORT(R,s1,t1)
rectype R[n];
int s1,t1;
{ int i;
if(s1<t1)
{ i=PARTITION(R,s1,t1);
QUICKSORT(R,s1,i-1);
QUICKSORT(R,i+1,t1);
}
}
SIFT(rectype R[n],int i,int m)
{int j;
rectype temp;
temp=R[i];
j=2*i;
while(j<=m)
{ if((j<m)&&(R[j].key<R[j+1].key))
j++;
if(temp.key<R[j].key)
{ R[i]=R[j];
i=j;
j=2*i;
}
else break;
}
R[i]=temp;
}
HEAPSORT()
{ int i;rectype R[n];
rectype temp;
enter();
for(i=1;i<4;i++)
R[i].key=d[i].score;
for(i=n/2;i>=1;i--)
SIFT(R,i,n);
for(i=n;i>=1;i--)
{ temp=R[1];
R[1]=R[i];
R[i]=temp;
SIFT(R,1,i-1);
}
for(i=1;i<n;i++)
{
d[i].score=R[i].key;
printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
}
void main()
{ int c;int i; rectype R[n];
do {
printf("\n=======================================================\n");
printf("1.insertsort\n");
printf("2.bubblesort\n");
printf("3.selectsort\n");
printf("4.quicksort\n");
printf("5.heapsort\n");
printf("0.exit\n");
printf("\n========================================================\n");
printf("please enter your choice:\n");
scanf("%d",&c);
switch(c)
{ case 1:
INSERTSORT();
break;
case 2:
BUBBLESORT();
break;
case 3:
SELECTSORT();
break;
case 4:
enter();
for(i=1;i<4;i++)
R[i].key=d[i].score;
QUICKSORT(R,0,n-1);
for(i=1;i<n;i++)
{
d[i].score=R[i].key;
printf("the information of student%d :\n",i);
printf("%ld\t%s\t%c\t%d\t%s\t%d\n",d[i].num,d[i].name,d[i].sex,d[i].age,
d[i].major,d[i].score);
}
break;
case 5:
HEAPSORT();
break;
case 0:
exit(0);
break;
}}while(1);
}

总是报2605的错误
...全文
157 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cocoabird 2012-11-22
  • 打赏
  • 举报
回复
代码规范点 加点注释比较好
ljhhh0123 2012-11-22
  • 打赏
  • 举报
回复
如果是排序就单写排序的代码,测试好了再运用到程序中,否则就用库里的qsort,这能使你快速的开发出程序. 写一点,测试一点,增量式开发.
漫步者、 2012-11-22
  • 打赏
  • 举报
回复
QUICKSORT(R,s1,t1)//少了分号
rectype R[n];
int s1,t1;
{ int i;
  if(s1<t1)
  { i=PARTITION(R,s1,t1);
    QUICKSORT(R,s1,i-1);
    QUICKSORT(R,i+1,t1);
  }

//这段代码你到底是要放哪里?
hznat 2012-11-22
  • 打赏
  • 举报
回复
你这个代码太乱了。 整理好格式,不然你下次再看的时候根本看不清啊。 然后复制你的代码到VC中,编译了一下,都是很明显的错误。。我觉的这种你还是自己先改改吧。
赵4老师 2012-11-22
  • 打赏
  • 举报
回复
单步调试和设断点调试是程序员必须掌握的技能之一。

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧