【发布时间】:2021-12-25 23:35:36
【问题描述】:
我有一个由学生组成的学生班级
- 姓氏
- 名字
- 生日
- 身份证
- 课程
- 电话号码
我必须使用选择排序来按这三个属性对给定的学生列表进行排序:
- 生日
- 姓氏
- 名字
我什至不知道从哪里开始,因为所有在线示例都展示了如何对数字数组进行排序。这就是我现在所拥有的,这绝对是不正确的。
public void MinMax(StudentsRegister other)
{
StudentsRegister AllYearStudents = new StudentsRegister();
for (int i = 0; i < AllYearStudents.StudentsCount() - 1; i++)
{
int smallest = i;
for (int j = i + 1; j < AllYearStudents.StudentsCount(); j++)
{
if (AllYearStudents.Get(j) < other.Get(smallest))
{
smallest = j;
}
}
}
}
【问题讨论】:
-
嗨@rokenga,你能提供输入和预期输出吗?您是要按所有三个属性排序,还是先使用
DOB搜索它,如果DOB相同,则使用LastName。如果DOB和LastName都相同,那么FirstName -
@PrasadTelkikar 如果我正确理解了这个问题,我想按所有三个属性排序,不管是升序还是降序。
-
@rokenga 你是说这个
yourList.OrderBy(x => x.Birthdate).OrderBy(x => x.LastName).OrderBy(x => x.FirstName)? -
@viveknuna 我需要使用选择排序
-
@CaiusJard 感谢您的改进
标签: c# oop selection-sort