package com.test.test;
import java.util.Arrays;
/**
* [说明/描述]
*
* @author CaiHaiming
* @date 2016-6-4 下午7:00:07
* @company chm
* @version 1.0
* @copyright copyright (c) 2016
*/
public class Sort1 {
public static void main(String[] args) {
int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
sort1(arr);
System.out.println(Arrays.toString(arr));
}
public static void sort1(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
Sort2.swap(arr, i, j);
}
}
}
}
}
package com.test.test;
import java.util.Arrays;
/**
* [说明/描述]
*
* @author CaiHaiming
* @date 2016-6-4 下午7:00:07
* @company chm
* @version 1.0
* @copyright copyright (c) 2016
*/
public class Sort2 {
<span style="white-space:pre"> </span>public static void main(String[] args) {
<span style="white-space:pre"> </span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
<span style="white-space:pre"> </span>sort1(arr);
<span style="white-space:pre"> </span>System.out.println(Arrays.toString(arr));
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public static void sort1(int[] arr) {
<span style="white-space:pre"> </span>for (int i = 0; i < arr.length - 1; i++) {
<span style="white-space:pre"> </span>for (int j = 0; j < arr.length - i - 1; j++) {
<span style="white-space:pre"> </span>if (arr[j] > arr[j + 1]) {
<span style="white-space:pre"> </span>swap(arr, j, j + 1);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public static void swap(int[] arr, int i, int j) {
<span style="white-space:pre"> </span>int temp = arr[i];
<span style="white-space:pre"> </span>arr[i] = arr[j];
<span style="white-space:pre"> </span>arr[j] = temp;
<span style="white-space:pre"> </span>}
}
package com.test.test;
import static java.util.Arrays.sort;
import java.util.Arrays;
/**
* [说明/描述]
*
* @author CaiHaiming
* @date 2016-6-4 下午7:00:07
* @company chm
* @version 1.0
* @copyright copyright (c) 2016
*/
public class Sort3 {
<span style="white-space:pre"> </span>public static void main(String[] args) {
<span style="white-space:pre"> </span>int[] arr = { 123, 2, 23, 134, 1, 123, 12312 };
<span style="white-space:pre"> </span>sort(arr);
<span style="white-space:pre"> </span>System.out.println(Arrays.toString(arr));
<span style="white-space:pre"> </span>}
}