import java.util.Arrays;
class Sort {
public static void main(String[] args) {
int[] arr = new int[]{1,4,7,2,5,8,3,6,9};
sort1(arr);
System.out.println(Arrays.toString(arr));
}
public static void sort1(int[] arr) {
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr.length-i-1; j++) {
if(arr[j] > arr[j+1]) {
swap(arr, j, j + 1);
}
}
}
}
public static void swap(int[] arr, int x, int y) {
int t = arr[x];
arr[x] = arr[y];
arr[y] = t;
}
} |
|