Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Created August 8, 2020 00:34
Show Gist options
  • Save goyuninfo/1542d3e8bc50f69a788d2c77c7dea278 to your computer and use it in GitHub Desktop.
Save goyuninfo/1542d3e8bc50f69a788d2c77c7dea278 to your computer and use it in GitHub Desktop.
static void bubbleSort(int[] lst) {
int n = lst.length;
boolean swapped;
do
{
swapped = false;
for (int i = 0; i < n-1; i++) {
if (lst[i] > lst[i+1]) {
int temp = lst[i];
lst[i] = lst[i+1];
lst[i+1] = temp;
swapped = true;
}
}
} while (swapped == true)
System.out.println(Arrays.toString(lst));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment