Skip to content

Instantly share code, notes, and snippets.

@perforb
Last active September 22, 2016 15:33
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 perforb/2dda9ce7a8388a4e8a469eea7525864b to your computer and use it in GitHub Desktop.
Save perforb/2dda9ce7a8388a4e8a469eea7525864b to your computer and use it in GitHub Desktop.
package algorithm;
import java.util.Arrays;
public class BubbleSort
{
public static void main(String[] args)
{
int[] ints = {23220, 82319, 22, 9023090, 239, 11634};
boolean flag = false;
do {
flag = false;
for (int i = 0, j = 0; i < ints.length -1 - j; i++) {
if (ints[i] > ints[i + 1]) {
int tmp = ints[i];
ints[i] = ints[i + 1];
ints[i + 1] = tmp;
flag = true;
j++;
}
}
}
while (flag);
Arrays.stream(ints).forEach(System.out::println);
}
}
22
239
11634
23220
82319
9023090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment