
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 知识点 { class Program { //用户自定义:我们自己定义这种数据类型 public struct student { public int code;//成员变量 public string name; public double degree; } //冒泡排序 public student[] paixu(student[] shuzu) { ; i < shuzu.Length-; i++) { ; j < shuzu.Length; j++) { if (shuzu[i].degree < shuzu[j].degree) { student zhong = new student();//定义一个新的结构体 zhong = shuzu[i]; shuzu[i] = shuzu[j]; shuzu[j] = zhong; } } } return shuzu; } //主函数:一个程序有且只有一个 static void Main(string[] args) { //1.输入学生信息 Console.Write("输入学生人数:"); int renshu = int.Parse(Console.ReadLine()); student [] shuzu= new student[renshu];//根据人数定义数组容器 ; i < renshu; i++)//跟据人数去循环输入学生信息 { //student s = new student();//s 是student 类型制造出来的:对象 Console.Write(); shuzu[i].code = int.Parse(Console.ReadLine()); Console.Write(); shuzu[i].name = Console.ReadLine(); Console.Write(); shuzu[i].degree = double.Parse(Console.ReadLine()); } //2.排序 shuzu=new Program().paixu(shuzu); /*for (int i = 0; i < renshu; i++) { for (int j = i + 1; j < renshu; j++) { if (shuzu[i].degree < shuzu[j].degree) { student zhong = new student();//定义一个新的结构体 zhong = shuzu[i]; shuzu[i] = shuzu[j]; shuzu[j] = zhong; } } }*/ //3.输出 Console.WriteLine("************成绩如下**************"); Console.WriteLine(" 学号 姓名 分数"); foreach (student s in shuzu)//阅历 结构体s { Console.Write(" "); Console.Write(s.code); Console.Write(" "); Console.Write(s.name); Console.Write(" "); Console.WriteLine(s.degree); } Console.ReadLine(); ; i < renshu; i++) { } } } }