public UnidirectionalList(UnidirectionalList <T> unidirectionalList)
 {
     Reset();
     foreach (T data in unidirectionalList)
     {
         Add(data);
     }
 }
Example #2
0
        public void TestMethod4()
        {
            var list = new UnidirectionalList();

            list.AddToEnd(new Organization("Организация1", "Город1", 103));
            list.AddToEnd(new Organization("Организация2", "Город2", 503));
            list.AddToStart(new Organization("Организация3", "Город3", 303));

            var expectedList = new UnidirectionalList();

            list.DeleteList();

            Assert.AreEqual(expectedList.Count, list.Count);
        }
Example #3
0
        public void TestMethod5()
        {
            var list = new UnidirectionalList();

            list.AddToEnd(new Organization("Организация1", "Город1", 103));
            list.AddToEnd(new Organization("Организация2", "Город2", 503));
            list.AddToStart(new Organization("Организация3", "Город3", 303));

            var expectedList = new UnidirectionalList();

            expectedList.AddToEnd(new Organization("Организация1", "Город1", 103));
            expectedList.AddToEnd(new Organization("Организация2", "Город2", 503));
            expectedList.AddToStart(new Organization("Организация3", "Город3", 303));

            list.RemoveAt(1);
            list.RunTask();

            expectedList.RemoveAt(1);
            Organization actual   = null;
            Organization expected = null;
            int          i        = 0;

            foreach (Organization org1 in list)
            {
                if (i == 1)
                {
                    actual = org1;
                }
                i++;
            }


            i = 0;
            foreach (Organization org2 in expectedList)
            {
                if (i == 1)
                {
                    expected = org2;
                }
                i++;
            }


            Assert.AreEqual(expected, actual);
        }
Example #4
0
        static UIClickablesHandler()
        {
            _clickables = UnidirectionalList <IUIClickable> .Create();

            _dragables = UnidirectionalList <IUIDragable> .Create();
        }
Example #5
0
        private bool MenuTask1()
        {
            try
            {
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("\nМЕНЮ\n");
                Console.ResetColor();
                Console.Write("   1.  Создать рандомный однонаправленный список\n" +
                              "   2.  Добавить рандомные элементы однонаправленный список\n" +
                              "   3.  Вывести однонаправленный список\n" +
                              "   4.  Удалить элемент из однонаправленного списка по индексу\n" +
                              "   5.  Удалить элемент из однонаправленного списка по имени\n" +
                              "   6.  Очистить однонаправленный список\n" +
                              "   7.  Создать рандомный двунаправленный список\n" +
                              "   8.  Добавить рандомные элементы двунаправленный список\n" +
                              "   9.  Вывести двунаправленный список\n" +
                              "   10. Удалить элемент из двунаправленного списка по индексу\n" +
                              "   11. Добавить в двунаправленный список элемент по индексу\n" +
                              "   12. Очистить двунаправленный список\n" +
                              "   13. Создать дерево поиска из рандомных элементов\n" +
                              "   14. Добавить элемент в дерево поиска\n" +
                              "   15. Вывести дерево поиска\n" +
                              "   16. Удалить элемент из дерева по значению\n" +
                              "   17. Сбалансировать дерево\n" +
                              "   18. Вывести минимальное и максимальное значения \n" +
                              "   19. Очистить дерево\n" +
                              "   20. Вернуться в главное меню\n" +
                              "\nВыберите задание: ");
                string str;
                switch (int.Parse(Console.ReadLine()))
                {
                case 1:
                    str = "=";
                    str = str.PadRight(Console.WindowWidth, '=');
                    Console.WriteLine(str);
                    Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2);
                    Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight);
                    {
                        unidirectionalList = new UnidirectionalList <Vehicle>();
                        Console.Write("Введите количество элементов: ");
                        int    x;
                        Random random = new Random();
                        while (!int.TryParse(Console.ReadLine(), out x))
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Неверный формат числа");
                            Console.ResetColor();
                        }

                        for (int i = 0; i < x; i++)
                        {
                            switch (random.Next(0, 4))
                            {
                            case 0:
                                unidirectionalList.Add((Vehicle)vehicle.Init());
                                //Debug.Print("0");
                                break;

                            case 1:
                                unidirectionalList.Add((Car)car.Init());
                                //Debug.Print("1");
                                break;

                            case 2:
                                unidirectionalList.Add((Train)train.Init());
                                //Debug.Print("2");
                                break;

                            case 3:
                                unidirectionalList.Add((Express)express.Init());
                                //Debug.Print("3");
                                break;
                            }
                        }
                        Console.WriteLine("Получившийся список:\n" + unidirectionalList);
                    }
                    Console.WriteLine();
                    return(true);

                case 2:
                    str = "=";
                    str = str.PadRight(Console.WindowWidth, '=');
                    Console.WriteLine(str);
                    Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2);
                    Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight);
                    {
                        Console.Write("Введите количество элементов: ");
                        int    x;
                        Random random = new Random();
                        while (!int.TryParse(Console.ReadLine(), out x))
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Неверный формат числа");
                            Console.ResetColor();
                        }

                        for (int i = 0; i < x; i++)
                        {
                            switch (random.Next(0, 4))
                            {
                            case 0:
                                unidirectionalList.Add((Vehicle)vehicle.Init());
                                //Debug.Print("0");
                                break;

                            case 1:
                                unidirectionalList.Add((Car)car.Init());
                                //Debug.Print("1");
                                break;

                            case 2:
                                unidirectionalList.Add((Train)train.Init());
                                //Debug.Print("2");
                                break;

                            case 3:
                                unidirectionalList.Add((Express)express.Init());
                                //Debug.Print("3");
                                break;
                            }
                        }
                        Console.WriteLine("Получившийся список:\n" + unidirectionalList);
                    }
                    Console.WriteLine();
                    return(true);

                case 3:
                    str = "=";
                    str = str.PadRight(Console.WindowWidth, '=');
                    Console.WriteLine(str);
                    Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2);
                    Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight);
                    {
                        Console.WriteLine(unidirectionalList);
                    }
                    return(true);

                case 4:
                    str = "=";
                    str = str.PadRight(Console.WindowWidth, '=');
                    Console.WriteLine(str);
                    Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2);
                    Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight);
                    {
                        Console.Write("Введите номер элемента: ");
                        int x;
                        while (!int.TryParse(Console.ReadLine(), out x))
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Неверный формат числа");
                            Console.ResetColor();
                        }
                        unidirectionalList.Remove(x);
                        Console.WriteLine("Получившийся список:\n" + unidirectionalList);
                    }
                    return(true);

                case 5:
                    str = "=";
                    str = str.PadRight(Console.WindowWidth, '=');
                    Console.WriteLine(str);
                    Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2);
                    Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight);
                    unsafe
                    {