Skip to content

Instantly share code, notes, and snippets.

@TwiN
Created March 26, 2016 23:01
Show Gist options
  • Save TwiN/cfd5d6b2996a8c057b23 to your computer and use it in GitHub Desktop.
Save TwiN/cfd5d6b2996a8c057b23 to your computer and use it in GitHub Desktop.
Java bubbleSort
public static void bubbleSort(int[] myList) { //USE: bubbleSort(myArray);
boolean flag = true;
while(flag) {
flag = false;
for(int i = 0; i < myList.length -1; i++) {
if(myList[i] < myList[i+1]) { // swap < for > to change from ascending to descending
int temp = myList[i];
myList[i] = myList[i+1];
myList[i+1] = temp;
flag = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment