1 package method.sort;
2
3 public class SwapSort
4 {
5 //交换排序方法
6 public static void swapSort(int[] array)
7 {
8 for(int i = 0; i < array.length; i++)
9 {
10 for(int j = i + 1; j < array.length; j++)
11 {
12 if(array[i] > array[j])
13 {
14 //交换两数字
15 array[i] = array[i] + array[j];
16 array[j] = array[i] - array[j];
17 array[i] = array[i] - array[j];
18 }
19 }
20 }
21 }
22
23 public static void main(String[] args)
24 {
25 int[] array = new int[]{3, 9, 2, 5, 7, 1, 3, 10, 0};
26
27 swapSort(array);
28
29 for(int i = 0; i < array.length;)
30 {
31 System.out.print(array[i] + "\t");
32 if(++i % 5 == 0)
33 {
34 System.out.println();
35 }
36 }
37 }
38 }
2
3 public class SwapSort
4 {
5 //交换排序方法
6 public static void swapSort(int[] array)
7 {
8 for(int i = 0; i < array.length; i++)
9 {
10 for(int j = i + 1; j < array.length; j++)
11 {
12 if(array[i] > array[j])
13 {
14 //交换两数字
15 array[i] = array[i] + array[j];
16 array[j] = array[i] - array[j];
17 array[i] = array[i] - array[j];
18 }
19 }
20 }
21 }
22
23 public static void main(String[] args)
24 {
25 int[] array = new int[]{3, 9, 2, 5, 7, 1, 3, 10, 0};
26
27 swapSort(array);
28
29 for(int i = 0; i < array.length;)
30 {
31 System.out.print(array[i] + "\t");
32 if(++i % 5 == 0)
33 {
34 System.out.println();
35 }
36 }
37 }
38 }