希尔排序

2018-12-14  本文已影响4人  Geniune
//9817543260
//希尔排序
int a[10] = {9, 8, 1, 7, 5, 4, 3, 2, 6, 0};

int n = sizeof(a)/sizeof(a[0]);

int h = 1;
while(h < n/3){
    h = 3 * h + 1;
}

while (h >= 1) {
    
    for(int i = h;i < n;i ++){
        
        int e = a[i];
        
        int j;
        for(j = i;j >= h && e < a[j - h];j -= h){
            
            a[j] = a[j - h];
        }
        a[j] = e;
    }
    h /= 3;
}

NSLog(@"排序结束");
上一篇下一篇

猜你喜欢

热点阅读