import java.util.Arrays;
import junit.framework.TestCase;
/**
* 插入排序
*
* @author jsczxy2
*
*/
public class InsertSort extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}
private void insertSort(int[] a) {
int i, j, temp;
for (i = 1; i < a.length; i++) {
temp = a[i];
for (j = i; j > 0; j--) {
if (a[j - 1] > temp) {
a[j] = a[j - 1];
} else
break;
}
a[j] = temp;
}
}
public void test() {
int a[] = { 4, 2, 6, 12, 7, 9, 1 };
insertSort(a);
System.out.println(Arrays.toString(a));
}
}