Last active
May 23, 2021 10:59
-
-
Save lifeparticle/538d9489daa5bc0cdffeba3dd761d769 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Main { | |
public static void main (String args[]) { | |
bubbleSort(new int [] {1, 4, 7, 10, 2}); | |
} | |
public static void bubbleSort(int[] arr) { | |
boolean isSorted = false; | |
int j = 1, i; | |
int tmp; | |
while (!isSorted) { | |
isSorted = true; | |
for (i = 0; i < arr.length - j; ++i) { | |
if (arr [i] > arr [i + 1]) { | |
tmp = arr [i]; | |
arr [i] = arr [i + 1]; | |
arr [i + 1] = tmp; | |
isSorted = false; | |
} | |
} | |
j++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment