Skip to content

Instantly share code, notes, and snippets.

@Climber24
Last active January 24, 2017 16:01
Show Gist options
  • Save Climber24/c8d63caab7318554e0e533652755b9e2 to your computer and use it in GitHub Desktop.
Save Climber24/c8d63caab7318554e0e533652755b9e2 to your computer and use it in GitHub Desktop.
JAVA Alternative bubble sorting with do-while cycle and boolean variable
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