Ejemplo n.º 1
0
 public static void Sdvig(ref int[] arr)
 //Сдвиг одномерного массива влево на заданное кол-во элементов
 {
     if (arr.Length == 0)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("\n Массив пуст, операция невозможна.");
         Console.ForegroundColor = ConsoleColor.White;
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine("\n На сколько элементов нужно сдвинуть массив?");
         int M = CreatingArrays.EnterForArray();
         for (int p = 0; p < M; p++)
         {
             int mind = arr[0];
             for (int i = 1; i < arr.Length; i++)
             {
                 arr[i - 1] = arr[i];
             }
             arr[arr.Length - 1] = mind;
         }
     }
     OutputArrays.OutputArray(arr);
     Console.WriteLine();
 }
Ejemplo n.º 2
0
        public static void Add(ref int[] arr)
        //Добавление заданного кол-ва элементов с заданного номера
        {
            if (arr.Length == 0)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\n Массив пуст, поэтому нужно добавлять элементы с номера '1'.");
                Console.ForegroundColor = ConsoleColor.White;
            }
            int adds, num, k, j = 0, i = 0;

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\n Введите кол-во элементов, которое хотите добавить:");
            adds = CreatingArrays.EnterForArray();
            Console.WriteLine("\n Введите номер элемента, с которого нужно вставить элементы");
            do
            {
                num = CreatingArrays.EnterForArray();
                if ((num > arr.Length + 1) || (num < 1))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\n Извините, такого номера в данном массиве не существует. Попробуйте ещё раз:");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            } while ((num > arr.Length + 1) || (num < 1));
            num--;
            int[] newarr = new int[arr.Length + adds];
            for (i = 0; i < num; i++)
            {
                newarr[i] = arr[i];
            }
            for (i = num; i < arr.Length; i++)
            {
                newarr[i + adds] = arr[i];
            }
            arr = newarr;
            k   = AddSelection();
            if (k == 1)
            {
                ArrayFilling.Hand(num + adds, ref arr, num);
            }
            else
            {
                ArrayFilling.Random(num + adds, ref arr, num);
            }
            OutputArrays.OutputArray(arr);
            Console.WriteLine();
        }
Ejemplo n.º 3
0
 public static void DeleteNum(ref int[] arr)
 //Удаление элемента массива с заданным номером
 {
     if (arr.Length == 0)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("\n Массив пуст, операция невозможна.");
         Console.ForegroundColor = ConsoleColor.White;
     }
     else
     {
         int i, num;
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine("\n Введите номер элемента, который хотите удалить:");
         do
         {
             num = CreatingArrays.EnterForArray();
             if ((num > arr.Length) || (num == 0))
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine("\n Ошибка, ожидался номер элемента, существующий в данном массиве. Попробуйте ещё раз:");
                 Console.ForegroundColor = ConsoleColor.White;
             }
         }while ((num > arr.Length) || (num == 0));
         int   m      = arr.Length - 1;
         int[] newarr = new int[m];
         for (i = 0; i < num - 1; i++)
         {
             newarr[i] = arr[i];
         }
         for (i = num - 1; i < m; i++)
         {
             newarr[i] = arr[i + 1];
         }
         arr = newarr;
     }
     OutputArrays.OutputArray(arr);
     Console.WriteLine();
 }