|
# include <iostream.h> //按学号输出学生的相关资料:
# include <string.h>
struct students {
char num [6];
char name [10];
int greag ;
};
students a[4]=
{
{"af321" , "周润法" , 78 }, {"ad321" , "水均益" , 93 },
{"aa321" , "张朝阳" , 85 }, {"ag321" , "刘翔" , 75 }
};
void range(int n)//应用的是插入排序法
{
for(int i=1;i<n;i++)
{
students d=a[i];
int j;
for (j=1;j>0 && strcmp(a[j-1].num,d.num)>0;j--)
a[j]=a[j-1];
a[j]=d;
}
for (i=0;i<n;i++)
cout<<a[i].num<<' '<<a[i].name<<' '<<a[i].greag<<endl; //结果输出排序是不正确的?请大家指点!
}
void main()
{
int m=4;
range (m);
} |
|