# 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�