Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 21, 2016 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustarc/621ee7220ceeb28a60c15399082a9719 to your computer and use it in GitHub Desktop.
Save agustarc/621ee7220ceeb28a60c15399082a9719 to your computer and use it in GitHub Desktop.
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