Skip to content

Instantly share code, notes, and snippets.

@bodrulamin
Created July 30, 2021 13:22
Show Gist options
  • Save bodrulamin/ddf4acb62a93350a5b6753a569f43101 to your computer and use it in GitHub Desktop.
Save bodrulamin/ddf4acb62a93350a5b6753a569f43101 to your computer and use it in GitHub Desktop.
public static int[] bubbleSort(int[] list) {
boolean needNextPass = true;
for (int i = 1; i < list.length && needNextPass; i++) {
needNextPass = false;
for (int j = 0; j < list.length - i; j++) {
if (list[j] > list[j + 1]) {
int big = list[j];
list[j] = list[j + 1];
list[j + 1] = big;
needNextPass = true;
}
}
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment