Evil Science A whole load of stuff

15May/130

A simple bubble sort

A simple bubble sort which arranges the provided array of numbers from smallest to largest.

static void BubbleSort(ref int[] arr)
{
bool change = true;
int temp;

while (change)
{
change = false;
for (int i = 0; i < arr.GetLength(0) - 1; i++)
{
if (arr[i + 1] < arr[i])
{
change = true;
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
break;
}
}
}
}
Filed under: C# Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.