예제 #1
0
        private static void Swap(List <ClsSinhVien> lSV, int iA, int iB)
        {
            ClsSinhVien T = lSV[iA];

            lSV[iA] = lSV[iB];
            lSV[iB] = T;
        }
예제 #2
0
        static void Main(string[] args)
        {
            //THi CUOI KY MON CAU TRUC DU LIEU VA GIAI THUAT
            //MSSV: 1606020010
            //TEN: Huỳnh Trọng Đại

            ClsMenu            menu   = new ClsMenu();
            List <ClsSinhVien> listSV = new List <ClsSinhVien>();
            int iLuaChon;

            menu.AddItem("Nhap Sinh Vien");
            menu.AddItem("Sap Xep Heap Sort");
            menu.AddItem("Sap Xep Selection Sort");
            menu.AddItem("Tim Kiem");
            menu.AddItem("Xem Danh Sach");
            menu.AddItem("Thoat");

            do
            {
                iLuaChon = menu.DisplayMenu();
                if (iLuaChon == 0)
                {
                    ClsSinhVien sinhVien = new ClsSinhVien();
                    sinhVien.NhapThongTin();
                    listSV.Add(sinhVien);
                }
                if (iLuaChon == 1)
                {
                    ClsSort sort = new ClsSort(listSV);
                    listSV = sort.HeapSort(listSV);
                    Console.ReadKey(true);
                }
                if (iLuaChon == 2)
                {
                    ClsSort sort = new ClsSort(listSV);
                    sort.Selection(listSV);
                    Console.ReadKey(true);
                }
                if (iLuaChon == 3)
                {
                }
                if (iLuaChon == 4)
                {
                    Console.WriteLine("-----------------------");
                    Console.WriteLine("{0,-10}|{1,-15}|{2,-15}", "MSMH", "Ten MH", "Diem");
                    Console.WriteLine("-----------------------");
                    foreach (ClsSinhVien sv in listSV)
                    {
                        Console.WriteLine("{0,-10} {1,-15} {2,-15}", sv.Mssv, sv.Ten, sv.DiemTB);
                    }
                    Console.ReadKey(true);
                }
            }while(iLuaChon != 5);
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
예제 #3
0
        public List <ClsSinhVien> Selection(List <ClsSinhVien> A)
        {
            int iN = A.Count;


            for (int i = 0; i < iN - 1; i++)
            {
                int minIndex = i;
                for (int j = i + 1; j < iN; j++)
                {
                    if (A[j].DiemTB < A[i].DiemTB)
                    {
                        ClsSinhVien t = A[j];
                        A[j]     = A[i];
                        A[i]     = t;
                        minIndex = j;
                        //Console.ReadKey(true);
                    }
                }
                execute();
                //Console.ReadKey(true);
            }
            return(A);
        }
 public ClsSinhVien(ClsSinhVien sinhVien)
 {
     mssv   = sinhVien.Mssv;
     ten    = sinhVien.Ten;
     diemTB = sinhVien.DiemTB;
 }