-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble sorting
35 lines (35 loc) · 974 Bytes
/
bubble sorting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
namespace SortingExample
{
class Program
{
static void Main(string[] args)
{
int[] number = { 89, 76, 45, 92, 67, 12, 99 };
bool flag = true;
int temp;
int numLength = number.Length;
//sorting an array
for (int i = 1; (i <= (numLength - 1)) && flag; i++)
{
flag = false;
for (int j = 0; j < (numLength - 1); j++)
{
if (number[j + 1] > number[j])
{
temp = number[j];
number[j] = number[j + 1];
number[j + 1] = temp;
flag = true;
}
}
}
//Sorted array
foreach (int num in number)
{
Console.Write("\t {0}",num);
}
Console.Read();
}
}
}