private List <Vehicle> createList() { List <Vehicle> list = new(1000); for (int i = 0; i < 100000; i++) { switch (random.Next(4)) { case 0: list.Add((Vehicle)vehicle.Init()); break; case 1: list.Add((Car)car.Init()); break; case 2: list.Add((Train)train.Init()); break; case 3: list.Add((Express)express.Init()); break; } } return(list); }
private static bool Menu1() { try { Console.Write("\n 1. Добавить в коллекцию Vehicle\n" + " 2. Добавить в коллекцию Car\n" + " 3. Добавить в коллекцию Train\n" + " 4. Добавить в коллекцию Express\n" + "\nВыберите задание: "); switch (int.Parse(Console.ReadLine())) { case 1: { queue.Enqueue((Vehicle)vehicle.Init()); } return(false); case 2: { queue.Enqueue((Vehicle)car.Init()); } return(false); case 3: { queue.Enqueue((Vehicle)train.Init()); } return(false); case 4: { queue.Enqueue((Vehicle)express.Init()); } return(false); default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа"); Console.ResetColor(); Console.WriteLine(); return(true); } } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа"); Console.ResetColor(); return(true); } }
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 {
private static bool Menu1() { try { Console.Write("\n 1. Добавить в коллекцию Vehicle\n" + " 2. Добавить в коллекцию Car\n" + " 3. Добавить в коллекцию Train\n" + " 4. Добавить в коллекцию Express\n" + "\nВыберите задание: "); switch (int.Parse(Console.ReadLine())) { case 1: { Console.Write("Введите название элемента: "); object x = Console.ReadLine(); while (ht.ContainsKey(x)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Элемент с таким названием уже есть в коллекции"); Console.ResetColor(); Console.Write("Введите название элемента: "); x = Console.ReadLine(); } ht.Add(x, vehicle.Init()); } return(false); case 2: { Console.Write("Введите название элемента: "); object x = Console.ReadLine(); while (ht.ContainsKey(x)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Элемент с таким названием уже есть в коллекции"); Console.ResetColor(); Console.Write("Введите название элемента: "); x = Console.ReadLine(); } ht.Add(x, car.Init()); } return(false); case 3: { Console.Write("Введите название элемента: "); object x = Console.ReadLine(); while (ht.ContainsKey(x)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Элемент с таким названием уже есть в коллекции"); Console.ResetColor(); Console.Write("Введите название элемента: "); x = Console.ReadLine(); } ht.Add(x, train.Init()); } return(false); case 4: { Console.Write("Введите название элемента: "); object x = Console.ReadLine(); while (ht.ContainsKey(x)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Элемент с таким названием уже есть в коллекции"); Console.ResetColor(); Console.Write("Введите название элемента: "); x = Console.ReadLine(); } ht.Add(x, express.Init()); } return(false); default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа"); Console.ResetColor(); Console.WriteLine(); return(true); } } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа"); Console.ResetColor(); return(true); } }