Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp11
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите объём массива - ");
- int volume = Convert.ToInt32(Console.ReadLine());
- int[] array = new int[volume];
- Console.WriteLine("Заполните массив:");
- array = FillingArray(array);
- array = Shuffle(array);
- Console.WriteLine("Ваш массив перемешан:");
- DrawArray(array);
- }
- static int[] Shuffle(int[] array)
- {
- int index = default;
- int[] shuffleArray = new int[array.Length];
- int[] temporaryArray = array;
- for (int i = 0; i < array.Length; i++)
- {
- Random rnd = new Random();
- index = rnd.Next(0, array.Length - (i + 1));
- shuffleArray[i] = temporaryArray[index];
- temporaryArray = DeletValue(temporaryArray, index);
- }
- return shuffleArray;
- }
- static int[] DeletValue(int[] temporaryArray, int index)
- {
- int[] editedArray = new int[temporaryArray.Length - 1];
- for(int i = index; i< temporaryArray.Length - 1; i++)
- temporaryArray[i] = temporaryArray[i + 1];
- for (int i = 0; i < editedArray.Length; i++)
- editedArray[i] = temporaryArray[i];
- return editedArray;
- }
- static int[] FillingArray(int [] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write($"{i + 1} - ");
- array[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.Clear();
- return array;
- }
- static void DrawArray(int [] array)
- {
- for (int i = 0; i < array.Length; i++)
- Console.Write(array[i] + " ");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement