标签:排序 ios class 希尔排序 div 插入 shell main for
#include<iostream> using namespace std; int arr[]={11,12,51,23,64,23,68,1,12}; void shellsort1(int arr[]) { int i, j, gap; for (gap = 9 / 2; gap > 0; gap /= 2) //步长 for (i = 0; i < gap; i++) { //直接插入排序 for (j = i + gap; j < 9; j += gap) if (arr[j] < arr[j - gap]) { int temp = arr[j]; int k = j - gap; while (k >= 0 && arr[k] > temp) { arr[k + gap] = arr[k]; k -= gap; } arr[k + gap] = temp; } } } int main() { shellsort1(arr); for (int i=0; i<9; i++) cout<<arr[i]<<" "; }
标签:排序 ios class 希尔排序 div 插入 shell main for
原文地址:http://www.cnblogs.com/a863886199/p/6916846.html