求 大神讲一下这个程序的算法
#include<stdio.h>#include<malloc.h>
#include<string.h>
struct student
{ char name[50];
int num;
int grades;
};
void main()
{
int i=0,j,k,exchang;struct student exchange;
struct student *stu;
stu=(struct student *)malloc(100*sizeof(struct student));
printf("请输入学生的姓名,当姓名输入NULL时程序结束,按回车进入下一步");
scanf("%s",stu[i].name);
for(;strcmp(stu[i].name,"NULL");scanf("%s",stu[i].name))
{
printf("请输入学生的学号");
scanf("%d",&stu[i].num);
printf("请输入学生的成绩");
scanf("%d",&stu[i].grades);
i++;
}
i--;
for(k=i;k>0;k--)
for(j=i;j>i-k;j--)
{if(stu[j].num>stu[j-1].num)
{strcpy(exchange.name,stu[j].name);
strcpy(stu[j].name,stu[j-1].name);
strcpy(stu[j-1].name,exchange.name);
exchang=stu[j-1].num;
stu[j-1].num=stu[j].num;
stu[j].num=exchang;
exchang=stu[j-1].grades;
stu[j-1].grades=stu[j].grades;
stu[j].grades=exchang;
}
}
for(j=0;j<=i;j++)
printf("name=%s,num=%d,grades=%d\n",stu[j].name,stu[j].num,stu[j].grades);
while(1);
}