Advertisement
junniorrkaa

Сортировка чисел

Oct 17th, 2024 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[10];
  10.  
  11.             Random random = new Random();
  12.  
  13.             int minValue = 0;
  14.             int maxValue = 10;
  15.             int tempElement;
  16.             int shiftCounter = 0;
  17.             int numberOne = 1;
  18.  
  19.             bool isWorking = true;
  20.  
  21.             Console.WriteLine("Массив: ");
  22.  
  23.             for (int i = 0; i < array.Length; i++)
  24.             {
  25.                 array[i] = random.Next(minValue, maxValue);
  26.  
  27.                 Console.Write(array[i] + " ");
  28.             }
  29.  
  30.             Console.WriteLine("\n");
  31.  
  32.             while (isWorking)
  33.             {
  34.                 for (int i = 0; i < array.Length - numberOne; i++)
  35.                 {
  36.                     if (array[i] > array[i + numberOne])
  37.                     {
  38.                         tempElement = array[i];
  39.                         array[i] = array[i + 1];
  40.                         array[i + 1] = tempElement;
  41.                         shiftCounter++;
  42.                     }
  43.                 }
  44.  
  45.                 if (shiftCounter == 0)
  46.                 {
  47.                     isWorking = false;
  48.                 }
  49.  
  50.                 shiftCounter = 0;
  51.             }
  52.  
  53.             Console.WriteLine("Измененный массив: ");
  54.  
  55.             foreach (int element in array)
  56.             {
  57.                 Console.Write(element + " ");
  58.             }
  59.  
  60.             Console.WriteLine("\n");
  61.             Console.ReadKey();
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement