Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[10];
- Random random = new Random();
- int minValue = 0;
- int maxValue = 10;
- int tempElement;
- int shiftCounter = 0;
- int numberOne = 1;
- bool isWorking = true;
- Console.WriteLine("Массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minValue, maxValue);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine("\n");
- while (isWorking)
- {
- for (int i = 0; i < array.Length - numberOne; i++)
- {
- if (array[i] > array[i + numberOne])
- {
- tempElement = array[i];
- array[i] = array[i + 1];
- array[i + 1] = tempElement;
- shiftCounter++;
- }
- }
- if (shiftCounter == 0)
- {
- isWorking = false;
- }
- shiftCounter = 0;
- }
- Console.WriteLine("Измененный массив: ");
- foreach (int element in array)
- {
- Console.Write(element + " ");
- }
- Console.WriteLine("\n");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement