Created
December 21, 2016 19:36
-
-
Save agustarc/621ee7220ceeb28a60c15399082a9719 to your computer and use it in GitHub Desktop.
This file contains 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 class BubbleSort { | |
public static void bubbleSort(int[] arr) { | |
final int length = arr.length; | |
for (int i = 0; i < length; i++) { | |
for (int j = 0; j < length - i; j++) { | |
if (j + 1 < length && arr[j] > arr[j + 1]) { | |
arr[j] = arr[j] + arr[j + 1]; | |
arr[j + 1] = arr[j] - arr[j + 1]; | |
arr[j] = arr[j] - arr[j + 1]; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment