Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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