Skip to content

Instantly share code, notes, and snippets.

@ArielSaldana
Last active June 16, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArielSaldana/1cf3eea83e11ea99f8947cb17bbcc5cc to your computer and use it in GitHub Desktop.
Save ArielSaldana/1cf3eea83e11ea99f8947cb17bbcc5cc to your computer and use it in GitHub Desktop.
// 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