Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@YonLiud
Last active December 28, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonLiud/b2bb485fbeb0709b7d57cc6862c540b6 to your computer and use it in GitHub Desktop.
Save YonLiud/b2bb485fbeb0709b7d57cc6862c540b6 to your computer and use it in GitHub Desktop.
Bubble Array Sorting Method - C#
static int[] BubbleSort(int[] inputArray)
{
bool swapped;
int[] outputArray = inputArray;
for (int i = 0; i < ARRAY_SIZE; i++)
{
swapped = false;
for (int j = 0; j < ARRAY_SIZE - 1; j++)
{
if (outputArray[j] > outputArray[j + 1])
{
int temp = outputArray[j + 1];
outputArray[j + 1] = outputArray[j];
outputArray[j] = temp;
swapped = true;
}
}
if (!swapped)
{
break;
}
}
return outputArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment