class Program
{
struct student //定义一个student的结构体
{
public string name; //基本格式
public int code;
public int age;
public int fenshu;
}
static void Main(string[] args)
{
while (true)
{
ArrayList al = new ArrayList(); //定义一个新的集合
Console.Write("请输入人数:");
int renshu = Convert.ToInt32(Console .ReadLine ());
for (int i = 0; i < renshu ; i++)
{
student r = new student(); //定义一个student类型r的变量,可以存储数值
Console.Write("请输入学生姓名:");
r.name = Console.ReadLine();
Console.Write("请输入学生学号:");
r.code = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生年龄:");
r.age = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生分数:");
r.fenshu = Convert.ToInt32(Console.ReadLine());
al.Add(r); //把r的值代入到al这个集合里
}
for (int i = 0; i < renshu; i++) //按分数冒泡排序
{
for (int j = i; j < renshu -1; j++)
{
if (((student)al[i]).fenshu<((student)al[j+1]).fenshu ) //好好看这句代码,不好理解,student类型里从al里取值
{
student zhong ;
zhong = (student)al[i] ;
al[i] = al[j + 1];
al[j + 1] = zhong;
}
}
}
Console.WriteLine("排后学生顺序");
for (int i = 0; i < renshu ; i++)
{ //水平符输出
Console.WriteLine("姓名"+((student)al[i]).name+"\t学号"+((student)al[i]).code +"\t分数"+((student)al[i]).fenshu +"\t年龄"+((student)al[i]).age );
}
}
Console.ReadLine();