Last active
October 26, 2019 08:19
-
-
Save yaboong/cd47e3ac5a92c4e8d3d320752f42a975 to your computer and use it in GitHub Desktop.
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(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