Exemple #1
0
        //------------------------------------Xuat file json------------------------------------------------------
        static void XuatJson(List <HocSinh> Input)
        {
            LopHS XuatDS = new LopHS();

            XuatDS.SoLuong         = 10000;
            XuatDS.DanhSachHocSinh = Input;
            string json = JsonConvert.SerializeObject(XuatDS);

            File.WriteAllText(@"C:\Users\ADMIN\Desktop\DanhSachKetQuaJSON.json", json);
        }
Exemple #2
0
        //------------------------------------Xuat file Xml Cach 2------------------------------------------------------
        static void XuatXml2(List <HocSinh> Input)
        {
            LopHS XmlKetQua = new LopHS();

            XmlKetQua.DanhSachHocSinh = Input;

            XmlSerializer serializer = new XmlSerializer(typeof(LopHS));

            using (TextWriter textWriter = new StreamWriter(@"C:\Users\ADMIN\Desktop\DanhSachKetQua2.xml"))
            {
                serializer.Serialize(textWriter, XmlKetQua);
                textWriter.Close();
            }
        }
Exemple #3
0
        static void Main()
        {
            String json_data = File.ReadAllText(@"C:\Users\ADMIN\Desktop\DanhSach.json");

            LopHS List = JsonConvert.DeserializeObject <LopHS>(json_data);

            //try
            //{
            //    LopHS List = JsonConvert.DeserializeObject<LopHS>(json_data);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            List <HocSinh> DanhSach1 = new List <HocSinh>();
            List <HocSinh> DanhSach2 = new List <HocSinh>();
            List <HocSinh> DanhSach3 = new List <HocSinh>();
            List <HocSinh> DanhSach4 = new List <HocSinh>();
            List <HocSinh> DanhSach5 = new List <HocSinh>();

            foreach (HocSinh HS in List.DanhSachHocSinh)
            {
                DanhSach1.Add(HS);
                DanhSach2.Add(HS);
                DanhSach3.Add(HS);
                DanhSach4.Add(HS);
                DanhSach5.Add(HS);
            }
            TachTen(List.DanhSachHocSinh);
            InDanhSach(List.DanhSachHocSinh);

start:
            int ThuocTinh = LuaChon();

            if (ThuocTinh == 6)
            {
                Console.WriteLine("\n\n------------------Lua chon thuoc tinh sap xep--------------------");
                XuatJson(SapXep(DanhSach1, LuaChon()));
                Console.WriteLine(" Da xuat file ket qua sap xep !!!");
                Console.WriteLine("\n------------Close!!!------------");
                goto end;
            }

            if (ThuocTinh == 7)
            {
                Console.WriteLine("\n------------Close!!!------------");
                goto end;
            }

            if (ThuocTinh == 5)
            {
                InDanhSach(SapXepGTvaT(DanhSach5));
                goto end;
            }

            Stopwatch tg = new Stopwatch();

            //------------------------------Do thoi gian--------------------------------------------------------
            tg.Start();
            InDanhSach(SapXep(DanhSach1, ThuocTinh));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep qua List moi: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //-------------------------------Sap xep noi bot----------------------------------------------------
            tg.Start();
            InDanhSach(SapXepNoiBot(DanhSach2, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep noi bot: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------Sap xep Linq------------------------------------------------------
            tg.Start();
            InDanhSach(SapXepLinq(DanhSach3, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep Linq: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------Sap xep SelectionSort---------------------------------------------
            tg.Start();
            InDanhSach(SelectionSort(DanhSach4, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep SelectionSort: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------------------------------------------------------------------------
            goto start;
end:
            Console.ReadKey();
        }
Exemple #4
0
        static void Main()
        {
            String        xmlData         = File.ReadAllText(@"C:\Users\ADMIN\Desktop\DanhSach.xml");
            XmlSerializer DanhsachHocSinh = new XmlSerializer(typeof(LopHS));
            LopHS         XmlKetQua       = new LopHS();

            using (TextReader reader = new StringReader(xmlData))
            {
                XmlKetQua = (LopHS)DanhsachHocSinh.Deserialize(reader);
            }

            List <HocSinh> DanhSach1 = new List <HocSinh>();
            List <HocSinh> DanhSach2 = new List <HocSinh>();
            List <HocSinh> DanhSach3 = new List <HocSinh>();
            List <HocSinh> DanhSach4 = new List <HocSinh>();
            List <HocSinh> DanhSach5 = new List <HocSinh>();

            foreach (HocSinh HS in XmlKetQua.DanhSachHocSinh)
            {
                DanhSach1.Add(HS);
                DanhSach2.Add(HS);
                DanhSach3.Add(HS);
                DanhSach4.Add(HS);
                DanhSach5.Add(HS);
            }
            TachTen(XmlKetQua.DanhSachHocSinh);
            InDanhSach(XmlKetQua.DanhSachHocSinh);

start:
            int ThuocTinh = LuaChon();

            if (ThuocTinh == 6)
            {
                Console.WriteLine("------------------Lua chon thuoc tinh sap xep--------------------");

                XuatXml2(SapXep(DanhSach1, LuaChon()));

                Console.WriteLine(" Da xuat file ket qua sap xep !!!");
                Console.WriteLine("\n------------Close!!!------------");
                goto end;
            }

            if (ThuocTinh == 7)
            {
                Console.WriteLine("\n------------Close!!!------------");
                goto end;
            }

            if (ThuocTinh == 5)
            {
                InDanhSach(SapXepGTvaT(DanhSach5));
                goto end;
            }

            Stopwatch tg = new Stopwatch();

            //------------------------------Do thoi gian--------------------------------------------------------
            tg.Start();
            InDanhSach(SapXep(DanhSach1, ThuocTinh));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep qua List moi: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //-------------------------------Sap xep noi bot----------------------------------------------------
            tg.Start();
            InDanhSach(SapXepNoiBot(DanhSach2, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep noi bot: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------Sap xep Linq------------------------------------------------------
            tg.Start();
            InDanhSach(SapXepLinq(DanhSach3, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep Linq: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------Sap xep SelectionSort---------------------------------------------
            tg.Start();
            InDanhSach(SelectionSort(DanhSach4, LuaChon()));
            tg.Stop();
            Console.WriteLine("\nThoi gian thuc hien sap xep SelectionSort: " + tg.ElapsedMilliseconds + "ms.");
            tg.Reset();
            //--------------------------------------------------------------------------------------------------
            goto start;
end:
            Console.ReadKey();
        }