24 lines
No EOL
664 B
Java
24 lines
No EOL
664 B
Java
public class bubblesort {
|
|
public static void bubbleSort(int[] A) {
|
|
for (int k = 0; k < A.length - 1; k++) {
|
|
for (int i = 1; i < A.length - k; i++) {
|
|
if (A[i] < A[i - 1]) {
|
|
int temp = A[i];
|
|
A[i] = A[i - 1];
|
|
A[i - 1] = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
int[] array = {7,9,1,2,3,6,4,5,8,0};
|
|
|
|
bubbleSort(array);
|
|
|
|
for(int i=0; i<array.length; i++)
|
|
System.out.print(array[i] + " ");
|
|
|
|
System.out.println("");
|
|
}
|
|
} |