26
1
using System;
2
public class BubbleSort
3
// сортиране метод на мехурчето
4
{
5
public static void Main()
6
{
7
int[] array = new int[] { 9, 7, 6, 5, 4, 3, 2, 8 };
8
for (int i = 0; i < array.Length - 1; i++)
9
{
10
for (int j = 0; j < array.Length - 1; j++)
11
{
12
if (array[j] > array[j + 1]) // swap the elements
13
{
14
int tmp = array[j];
15
array[j] = array[j + 1];
16
array[j + 1] = tmp;
17
}
18
}
19
}
20
for (int i = 0; i < array.Length; i++) // print the elements
21
{
22
Console.Write(array[i] + " ");
23
}
24
}
25
}
26
Cached Result