Last active
December 28, 2020 12:40
-
-
Save YonLiud/b2bb485fbeb0709b7d57cc6862c540b6 to your computer and use it in GitHub Desktop.
Bubble Array Sorting Method - C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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