Advertisement
Makakas

Bubble

Mar 5th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Sort
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Не отсортированный массив: ");
  10.            
  11.             Random rnd = new Random();
  12.             var a = new int[100];
  13.             for (int i = 0; i < a.Length; i++)
  14.             {
  15.                 a[i] = rnd.Next(-100, 100);
  16.                 Console.Write("{0} ", a[i]);
  17.             }
  18.                 int max = 100;
  19.                 int imax = 0;
  20.                 int temp1;
  21.                 int c = 0;
  22.                 int L = a.Length - 1;
  23.                 Console.WriteLine();
  24.                 Console.WriteLine("Массив отсортированный Пузырьковым методом: ");
  25.  
  26.                 for (int i = 0; i < a.Length; i++)
  27.                 {
  28.                     for (int j = c; j < L; j++)
  29.                     {
  30.                         if (max == 100) { max = a[j]; }
  31.                         if (a[j] > a[j + 1])
  32.                         {
  33.                             temp1 = a[j];
  34.                             a[j] = a[j + 1];
  35.                             a[j + 1] = temp1;
  36.                             if (max > a[j])
  37.                             {
  38.                                 max = a[j]; imax = j;
  39.                                 temp1 = a[c];
  40.                                 a[c] = a[imax];
  41.                                 a[imax] = temp1;
  42.                             }}}
  43.                 c++; L--;
  44.                 max = 1000; imax = 0;
  45.             }
  46.                 for (int i = 0; i < a.Length; i++)
  47.                 {
  48.                     Console.Write("{0} ", a[i]);
  49.                 }
  50.                 Console.ReadKey();}}
  51.  
  52.    
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement