Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Sort
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Не отсортированный массив: ");
- Random rnd = new Random();
- var a = new int[100];
- for (int i = 0; i < a.Length; i++)
- {
- a[i] = rnd.Next(-100, 100);
- Console.Write("{0} ", a[i]);
- }
- int max = 100;
- int imax = 0;
- int temp1;
- int c = 0;
- int L = a.Length - 1;
- Console.WriteLine();
- Console.WriteLine("Массив отсортированный Пузырьковым методом: ");
- for (int i = 0; i < a.Length; i++)
- {
- for (int j = c; j < L; j++)
- {
- if (max == 100) { max = a[j]; }
- if (a[j] > a[j + 1])
- {
- temp1 = a[j];
- a[j] = a[j + 1];
- a[j + 1] = temp1;
- if (max > a[j])
- {
- max = a[j]; imax = j;
- temp1 = a[c];
- a[c] = a[imax];
- a[imax] = temp1;
- }}}
- c++; L--;
- max = 1000; imax = 0;
- }
- for (int i = 0; i < a.Length; i++)
- {
- Console.Write("{0} ", a[i]);
- }
- Console.ReadKey();}}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement