Last active
June 16, 2016 18:35
-
-
Save ArielSaldana/1cf3eea83e11ea99f8947cb17bbcc5cc 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
// if anyone ever wants a bubble sort implementation | |
/** | |
* Created by Ariel on 6/16/2016. | |
*/ | |
public class BubbleSort { | |
public static void sort ( int arr[] ) { | |
Boolean needsSorting = true; | |
int current = 0, next = 0; | |
while( needsSorting ) { | |
needsSorting = false; | |
for ( int i = 0; i < arr.length-1; i++ ) { | |
current = arr[i]; | |
next = arr[i+1]; | |
if ( next < current ) { | |
arr[i] = next; | |
arr[i+1] = current; | |
needsSorting = true; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment