Ejemplo n.º 1
0
        public object Clone()
        {
            LinkedListVector clone = new LinkedListVector(this.Length);

            for (int i = 0; i < this.Length; i++)
            {
                clone[i] = this[i];
            }
            return(clone);
        }
Ejemplo n.º 2
0
        public static IVector Sum(IVector x, IVector y)
        {
            IVector ans;

            if (x is ArrayVector)
            {
                ans = new ArrayVector(Math.Max(x.Length, y.Length));
            }
            else
            {
                if (x is LinkedListVector)
                {
                    ans = new LinkedListVector(Math.Max(x.Length, y.Length));
                }
                else
                {
                    Console.WriteLine("Операция неприменима к объектам данных типов\nPress Enter...");
                    Console.ReadLine();
                    throw new Exception();
                }
            }
            try
            {
                for (int i = 0; i < ans.Length; i++)
                {
                    ans[i] = x[i] + y[i];
                }
                return(ans);
            }
            catch (Exception)
            {
                Console.WriteLine("вектора имеют разную длину\nPress Enter...");
                Console.ReadLine();
                throw;
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            // создание массива
            Console.Write("ЛР-07. Черников В.Е. гр. № 6113. \n" +
                          "Программа для работы с векторами и односвязными списками,\n" +
                          "реализующими несколько стандарнтых интерфейсов (c использованием делегатa) \n" +
                          "Введите колличество векторов в массиве: ");
            int n = Int32.Parse(Console.ReadLine());

            arr = new IVector[n];
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Создание {0}-го вектора:\n" +
                                  "Выберете: 1. Вектор    2. Список", i + 1);
                int type = Int32.Parse(Console.ReadLine());
                Console.WriteLine("Введите размерность вектора: ");
                int     size = Int32.Parse(Console.ReadLine());
                IVector x;
                if (type == 1)
                {
                    x = new ArrayVector(size);
                }
                else
                {
                    x = new LinkedListVector(size);
                }
                Console.WriteLine("Введите элементы вектора: ");
                try
                {
                    for (int j = 0; j < size; j++)
                    {
                        x[j] = Double.Parse(Console.ReadLine());
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Неверный формат записи");
                    throw;
                }
                arr[i] = x;
            }

            // Меню
            Console.Clear();
            foreach (IVector x in arr)
            {
                Console.WriteLine(x.ToString());
            }
            Console.Write("Введите последовательность пунктов меню, которая должна быть выполнена:\n" +
                          "1. Найти самые маленькие вектора\n" +
                          "2. Найти самые большие вектора\n" +
                          "3. Сортировать массив по возрастанию модулей\n" +
                          "4. Сортировать массив по кол-ву координат\n" +
                          "5. Клонировать произвольный вектор\n" +
                          "Последовательность (в строчку, без пробелов): ");
            string buf             = Console.ReadLine();
            Del    delegateForMenu = null;

            foreach (char ch in buf)
            {
                switch (ch)
                {
                case '1':
                    delegateForMenu += Action1;
                    break;

                case '2':
                    delegateForMenu += Action2;
                    break;

                case '3':
                    delegateForMenu += Action3;
                    break;

                case '4':
                    delegateForMenu += Action4;
                    break;

                case '5':
                    delegateForMenu += Action5;
                    break;
                }
            }

            // запуск делегата
            delegateForMenu();
        }