Example #1
0
        public void Insert()
        {
            string malop, tenlop; int siso;
            //nhap ma ko trung
            NodeL tgl = new NodeL();
            bool  ok  = true;//mặc dịnh ma ko trung

            do
            {
                ok = true;
                Console.Write("nhap ma lop: ");
                malop = Console.ReadLine();
                tgl   = this.ds;
                while (tgl != null)
                {
                    if (string.Compare(malop, tgl.L.malop) == 0)
                    {
                        ok = false; break;
                    }
                    tgl = tgl.link;
                }
            }while(!ok);
            Console.Write("nhap ten lop: ");
            tenlop = Console.ReadLine();
            siso   = 0;
            NodeL tg = new NodeL();

            tg.L = new Lop(malop, tenlop, siso);  //???
            ghitep(tg);
            tg.link = null;
            tg.link = ds;
            ds      = tg;
        }
Example #2
0
        public void hoanvi(NodeL p, NodeL q)
        {
            NodeL tg = new NodeL();

            tg.L = p.L;
            p.L  = q.L;
            q.L  = tg.L;
        }
Example #3
0
        public void ghitep(NodeL tg)
        {
            StreamWriter fw = File.AppendText("Lop.txt");

            fw.WriteLine();
            fw.Write("{0}#{1}#{2}", tg.L.malop, tg.L.tenlop, tg.L.siso);
            fw.Close();
        }
Example #4
0
        public void doctep()
        {
            StreamReader fr = File.OpenText("lop.txt");

            ds = null; m = 0;
            NodeL  tg;
            string s;

            string[] con;      //cac truong DL
            s = fr.ReadLine(); //doc dong dau=> duoc ban ghi dau tien
            if (s != null)
            {
                con = new string[3];
                while (s != null)//lan luot doc het tep
                {
                    if (s.Length > 0)
                    {
                        con         = s.Split('#');
                        tg          = new NodeL(); tg.L = new Lop();
                        tg.L.malop  = con[0];
                        tg.L.tenlop = con[1];
                        tg.L.siso   = int.Parse(con[2]);
                        //them TT lop vua doc tu tep vao DS lop hoc ds
                        m++;
                        if (ds == null)
                        {
                            ds = tg;
                        }
                        else
                        {
                            tg.link = ds;
                            ds      = tg;
                        }

                        s = fr.ReadLine();
                    }
                }
            }
            else
            {
                Console.WriteLine("tep rong!!!");
            }
            Console.WriteLine("Du lieu vua doc duoc tu tep LOP.TXT nhu sau:");
            hienthi();
            fr.Close();
        }
Example #5
0
        int m;                         //so lop trong truong
        public void hienthi()
        {
            NodeL tg = new NodeL(); tg = this.ds;

            Console.WriteLine("Malop\tTenlop\tSiso");
            if (tg != null)
            {
                while (tg != null)
                {
                    Console.WriteLine("{0}\t{1}\t{2}", tg.L.malop, tg.L.tenlop, tg.L.siso);
                    tg = tg.link;
                }
            }
            else
            {
                Console.WriteLine("Danh sách trong");
            }
        }
Example #6
0
        public void Thongke()
        {
            StreamWriter ftk;

            if (File.Exists("Thongkekhoi.txt"))
            {
                ftk = File.AppendText("Thongkekhoi.txt");
            }
            else
            {
                ftk = File.CreateText("Thongkekhoi.txt");
            }
            int d10, d11, d12;

            d10 = d11 = d12 = 0;
            NodeL tg = this.ds;

            while (tg.link != null)
            {
                if (tg.L.malop.IndexOf("1215") >= 0)
                {
                    d12++;
                }
                if (tg.L.malop.IndexOf("1316") >= 0)
                {
                    d11++;
                }
                if (tg.L.malop.IndexOf("1417") >= 0)
                {
                    d10++;
                }
                tg = tg.link;
            }
            Console.WriteLine("So lop khoi 10   : {0} ", d10);
            Console.WriteLine("So lop khoi 11   : {0} ", d11);
            Console.WriteLine("So lop khoi 12   : {0} ", d12);
            DateTime dt = new DateTime();

            ftk.WriteLine("Thoi diem thong ke: {0}/{1}/{2}", dt.Day, dt.Month, dt.Year);
            ftk.WriteLine("So lop khoi 10   : {0} ", d10);
            ftk.WriteLine("So lop khoi 11   : {0} ", d11);
            ftk.WriteLine("So lop khoi 12   : {0} ", d12);
            ftk.Close();
        }