Created
March 25, 2019 20:40
-
-
Save leon-lourenco/2c132267a12024d932603f81b9186fa3 to your computer and use it in GitHub Desktop.
Bubble Sort Simple Example
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
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