(一)插入排序

思想:将每一个插入的元素,放置到合适的位置

void insertSort(int[] array, int length) {
        for(int i =1;i<length;i++){
            int tmp = array[i];
            int j = i;
            while(j>=1 && tmp<array[j-1]){
                array[j]=array[j-1];
                j--;
            }
            array[j] = tmp;
        }
    }

猜你喜欢

转载自www.cnblogs.com/lixiaopengcc/p/10841804.html