Last active
January 24, 2017 16:01
-
-
Save Climber24/c8d63caab7318554e0e533652755b9e2 to your computer and use it in GitHub Desktop.
JAVA Alternative bubble sorting with do-while cycle and boolean variable
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
public static void sort(int[] array) | |
{ | |
boolean thereIsBubbling; | |
int temp; | |
do { | |
thereIsBubbling = false; | |
for (int i = 0; i < array.length - 1; i++) | |
{ | |
if (array[i] > array[i + 1]) | |
{ | |
thereIsBubbling = true; | |
temp = array[i]; | |
array[i] = array[i + 1]; | |
array[i + 1] = temp; | |
} | |
} | |
} | |
while (thereIsBubbling); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment