-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC# program for a bubbleSort .txt
47 lines (34 loc) · 1.11 KB
/
C# program for a bubbleSort .txt
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
36
37
38
39
40
41
42
43
44
45
46
47
question
bubble sort program
full c#
using System;
namespace BubbleSort
{
internal class Program
{
static void Main(string[] args)
{
// Declarations
int[] array = { 1, 2, 4, 3, 5 };
BubbleSort(array);
Console.WriteLine(string.Join(", ", array));
}
static void BubbleSort(int[] array)
{
for (int i = 0; i < array.Length - 1; i++)
{
for (int j = 0; j < array.Length - i - 1; j++)
{
//checks if value is out of order by size.
if (array[j] > array[j + 1])
{
//if it is it takes the big number out of place and puts it inside a temp, it then put the smaller value inside the big numbers space and then puts the value stored inside the temp into the smaller numbers space.
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}
}
}