//----------------------------------Cach sap xep noi bot-------------------------------------------------- static List <HocSinh> SapXepNoiBot(List <HocSinh> Input, int ThuocTinh) { for (int i = 0; i < Input.Count; i++) { for (int j = i + 1; j < Input.Count; j++) { if (SoSanhPhanTu(Input[i], Input[j], ThuocTinh) == Input[j].ID) { HocSinh TG = Input[i]; Input[i] = Input[j]; Input[j] = TG; } } } return(Input); }
//----------------------------------Sap xep SelectionSort------------------------------------------------- public static List <HocSinh> SelectionSort(List <HocSinh> Input, int ThuocTinh) { int i, j, min; for (i = 0; i < Input.Count; i++) { min = i; for (j = i + 1; j < Input.Count; j++) { if (SoSanhPhanTu(Input[min], Input[j], ThuocTinh) == Input[j].ID) { min = j; } } HocSinh tg = Input[min]; Input[min] = Input[i]; Input[i] = tg; } //Console.WriteLine(String.Join(" -> ", List)); return(Input); }
//----------------------------------So sanh hai phan tu cung thuoc tinh----------------------------------- static int SoSanhPhanTu(HocSinh a, HocSinh b, int ThuocTinh) { switch (ThuocTinh) { case (int)HocSinh.Quydoi.Tuoi: if (SortNum(a.Tuoi, b.Tuoi) == a.Tuoi) { return(a.ID); } break; case (int)HocSinh.Quydoi.HoTen: if (SortText(a.HoTen, b.HoTen) == a.HoTen) { return(a.ID); } break; case (int)HocSinh.Quydoi.Ten: if (SortText(a.Ten, b.Ten) == a.Ten) { return(a.ID); } break; case (int)HocSinh.Quydoi.GioiTinh: if (SortText(a.GioiTinh, b.GioiTinh) == a.GioiTinh) { return(a.ID); } break; default: break; } return(b.ID); }