Example #1
0
 public MyStack(MyStack <T> c) //служит для создания коллекции, которая инициализируется элементами
 //и емкостью коллекции, заданной параметром с.
 {
     TrialLinkedList <T> newList = c.StackList;
 }
Example #2
0
        public static void StackMenu()
        {
            MyStack <Trial> m      = new MyStack <Trial>();
            int             choice = -1;

            while (choice != 9)
            {
                Console.WriteLine("1. Печать");
                Console.WriteLine("2. Подсчёт количества элементов в коллекции");
                Console.WriteLine("3. Добавить элементы");
                Console.WriteLine("4. Удалить элементы");
                Console.WriteLine("5. Найти элемент по значению");
                Console.WriteLine("6. Выполнить клонирование");
                Console.WriteLine("7. Выполнить поверхностное копирование");
                Console.WriteLine("8. Удалить коллекцию из памяти");
                Console.WriteLine("9. Назад");

                bool ok = int.TryParse(Console.ReadLine(), out choice);
                if (!ok)
                {
                    do
                    {
                        Console.WriteLine("Проверьте правильность ввода");
                        ok = int.TryParse(Console.ReadLine(), out choice);
                    } while (!ok || choice < 0 || choice > 9);
                }

                switch (choice)
                {
                case 1:
                    m.Show();
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Количество элементов коллекции = " + m.Count());
                    break;

                case 3:
                    Console.WriteLine("Введите количество элементов, которое необходимо добавить");
                    int  num;
                    bool boo = int.TryParse(Console.ReadLine(), out num);
                    if (!boo)
                    {
                        do
                        {
                            Console.WriteLine("Проверьте правильность ввода");
                            boo = int.TryParse(Console.ReadLine(), out num);
                        } while (!boo || num < 0);
                    }
                    m.Add(num, rnd);
                    Console.Clear();
                    Console.WriteLine($"Добавление {num} элементов выполнено");
                    break;

                case 4:
                    int capacity = m.Count();
                    Console.WriteLine("Введите количество элементов, которое необходимо удалить");
                    int number;
                    boo = int.TryParse(Console.ReadLine(), out number);
                    if (!boo || number < 0 || number > capacity)
                    {
                        do
                        {
                            Console.WriteLine("Проверьте правильность ввода");
                            boo = int.TryParse(Console.ReadLine(), out number);
                        } while (!boo || number < 0 || number > capacity);
                    }
                    m.Delete(number);
                    Console.Clear();
                    Console.WriteLine($"Удаление {number} элементов выполнено");
                    break;

                case 5:
                    Console.WriteLine("Введите значение Trial");
                    Console.WriteLine("День:");
                    int d = int.Parse(Console.ReadLine());
                    Console.WriteLine("Месяц:");
                    int mo = int.Parse(Console.ReadLine());
                    Console.WriteLine("Оценка:");
                    int   ma    = int.Parse(Console.ReadLine());
                    Trial trial = new Trial(d, mo, ma);
                    m.Search(trial);
                    break;

                case 6:
                    MyStack <Trial> newCollection = (MyStack <Trial>)m.Clone();
                    Console.WriteLine("Клонирование выполнено");
                    Console.WriteLine("Текущая коллекция:");
                    m.Show();
                    Console.WriteLine();
                    Console.WriteLine("Клонированная коллекция:");
                    newCollection.Show();
                    break;

                case 7:
                    MyStack <Trial> copyCollection = m.ShallowCopy();
                    Console.WriteLine("Копирование выполнено");
                    Console.WriteLine("Текущая коллекция:");
                    m.Show();
                    Console.WriteLine();
                    Console.WriteLine("Копированная коллекция:");
                    copyCollection.Show();
                    break;

                case 8:
                    m.Delete();
                    break;

                case 9:
                    choice = 9;
                    Console.Clear();
                    break;
                }
            }
        }