Skip to content

Instantly share code, notes, and snippets.

@yaboong
Last active October 26, 2019 08:19
Show Gist options
  • Save yaboong/cd47e3ac5a92c4e8d3d320752f42a975 to your computer and use it in GitHub Desktop.
Save yaboong/cd47e3ac5a92c4e8d3d320752f42a975 to your computer and use it in GitHub Desktop.
public static void sort(Integer[] a, int len) {
if (len <= 1) {
return;
}
boolean swapped = false;
for (int i=1; i<len; i++) {
if (a[i-1] > a[i]) {
swap(a, i, i-1);
swapped = true;
}
}
if (swapped) {
sort(a, len-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment