Skip to content

Instantly share code, notes, and snippets.

@leon-lourenco
Created March 25, 2019 20:40
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 leon-lourenco/2c132267a12024d932603f81b9186fa3 to your computer and use it in GitHub Desktop.
Save leon-lourenco/2c132267a12024d932603f81b9186fa3 to your computer and use it in GitHub Desktop.
Bubble Sort Simple Example
public class BubbleSortExample {
public static void main(String[] args) {
int[] literallyAnything = {10, 2, 39, 666, 1823, 38853, 31, 2, 64, 231, 7};
int[] show = bubbleSort(literallyAnything);
for (int a = 0; a < show.length; a++) {
System.out.println(show[a]);
}
}
public static int[] bubbleSort(int v[]) {
for (int i = v.length; i >= 1; i--) {
for (int j = 1; j < i; j++) {
if (v[j - 1] > v[j]) {
int aux = v[j];
v[j] = v[j - 1];
v[j - 1] = aux;
}
}
}
return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment