Created
March 26, 2016 23:01
-
-
Save TwiN/cfd5d6b2996a8c057b23 to your computer and use it in GitHub Desktop.
Java bubbleSort
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 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