Exemple #1
0
 public static void FileToList(GenericList <int> ds)
 {
     using (StreamReader sr = new StreamReader("Dayso.txt"))
     {
         var n = int.Parse(sr.ReadLine());
         for (int i = 0; i < n; i++)
         {
             var x = int.Parse(sr.ReadLine());
             ds.Addhead(x);
         }
     }
 }
Exemple #2
0
        public static void Input(GenericList <int> ds)
        {
            var x = 0;

            do
            {
                Console.Write("Nhap vao so nguyen duong (nhap -1 ket thuc): ");
                x = Int32.Parse(Console.ReadLine());
                if (x < 0)
                {
                    break;
                }
                else
                {
                    ds.Addhead(x);
                    //AddTail(pNew);
                }
            } while (true);
        }
Exemple #3
0
        public static void TestLL()
        {
            GenericList <int> ds;

            ds = new GenericList <int>();
            var ds1  = new GenericList <int>();
            var ds2  = new GenericList <int>();
            var ds3  = new GenericList <int>();
            var chon = 0;

            do
            {
                chon = MenuDSLK();
                switch (chon)
                {
                case 1:
                {
                    FileToList(ds); break;
                }

                case 2:
                {
                    Input(ds);
                    break;
                }

                case 3:
                {
                    ds.PrintAllNodes(); break;
                }

                case 4:
                {
                    Console.Write("PHAN TU CAN NHAP: ");
                    var n = int.Parse(Console.ReadLine());
                    ds.Addhead(n);
                    ds.PrintAllNodes();
                    break;
                }

                case 5:
                {
                    Console.Write("PHAN TU CAN NHAP: ");
                    var n = int.Parse(Console.ReadLine());
                    ds.AddLast(n);
                    ds.PrintAllNodes();
                    break;
                }

                case 6:
                {
                    ds.PrintAllNodes();
                    Console.Write("PHAN TU CAN TIM: ");
                    var n = int.Parse(Console.ReadLine());
                    Console.WriteLine("=> Phan tu {0} nam o vi tri {1} . ", n, ds.SearchNode1(n));
                    break;
                }

                case 7:
                {
                    ds.PrintAllNodes();
                    Console.Write("PHAN TU CAN XOA: ");
                    var n = int.Parse(Console.ReadLine());
                    ds.deleteallofX(n);
                    //ds.Delete(n);
                    ds.PrintAllNodes();
                    break;
                }

                case 8:
                {
                    Console.WriteLine("Phan tu lon nhat cua link list: " + ds.maxnode(new IntComparer()));
                    Console.WriteLine("Phan tu nho nhat cua link list: " + ds.minnode(new IntComparer()));
                    Console.Write("Phan tu chan cua link list: ");
                    Evennode(ds);
                    break;
                }

                case 9:
                {
                    FileTotwolist(ds1, ds2);
                    Console.WriteLine("+ Kiem tra tinh tang dan cua hai danh sach :");
                    if (ds1.isSortedAsc(ds1.Head, new IntComparer()) == true && ds2.isSortedAsc(ds2.Head, new IntComparer()) == true)
                    {
                        Console.WriteLine("Ca 2 danh sach nhap tu FILE dau tang dan");
                        ds1.PrintAllNodes();
                        ds2.PrintAllNodes();
                    }
                    else
                    {
                        Console.WriteLine("Out ra sua lai file");
                    }
                    //ds3.MergeSortedList(ds1.Head, ds2.Head);
                    //Console.Write("=> KET QUA danh sach 3: ");
                    //ds3.PrintAllNodes();
                    Console.Write("=> KET QUA danh sach 3: ");
                    Merge(ds1, ds2, ds3);
                    ds3.PrintAllNodes();
                    Console.WriteLine("\nPress any key to terminate...");
                    break;
                }

                case 10:
                {
                    break;
                }

                case 0:
                {
                    break;
                }

                default:
                {
                    Console.WriteLine("Hello");
                    break;
                }
                }
                Console.ReadKey();
                Console.Clear();
            } while (chon != 0);
        }