Skip to content

Instantly share code, notes, and snippets.

@Parithi
Created February 5, 2018 03:12
Show Gist options
  • Save Parithi/8ee804b980b2cdd2e33897063478a2ca to your computer and use it in GitHub Desktop.
Save Parithi/8ee804b980b2cdd2e33897063478a2ca to your computer and use it in GitHub Desktop.
Bubble Sort
package com.parithi;
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args) {
int[] array = {9,4,1,2,7,5,6,3,8};
System.out.println(Arrays.toString(array));
for(int j=0;j<array.length-1;j++) {
for (int i = array.length - 1; i > j; i--) {
int value1 = array[i];
int value2 = array[i - 1];
if (value1 < value2) {
array[i - 1] = value1;
array[i] = value2;
}
}
}
System.out.println(Arrays.toString(array));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment