码迷,mamicode.com
首页 > 编程语言 > 详细

希尔排序

时间:2017-02-26 17:06:18      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:***   stdio.h   好的   class   color   std   pre   blog   gap   

 

 1 /************************************************************************/
 2 /* 希尔排序,称为增量排序更好记忆
 3 /* 增量选取为N/2,虽不是个好的增量,但是便于理解
 4 /************************************************************************/
 5 #include <stdio.h>
 6 
 7 void ShellSort(int * array, int size)
 8 {
 9     int Gap, i, j;
10     int tmp;
11     for(Gap = size / 2; Gap > 0; Gap /= 2)
12     {
13         for(i = Gap; i < size; i += Gap)
14         {
15             tmp = array[i];
16             for(j = i; array[j - Gap] > tmp && j > 0; j -= Gap)
17             {
18                 array[j] = array[j - Gap];
19             }
20             array[j] = tmp;
21         }
22     }
23 }
24 
25 
26 int main()
27 {
28     int Array[10] = {5, 45, 36, 48, 20, 17, 84, 201, 92, 54};
29     for (int index = 0; index < 10; ++index)
30     {
31         printf("%d    ", Array[index]);
32     }
33 
34     ShellSort(Array, 10);
35 
36     printf("\r\n");
37 
38     for (int index = 0; index < 10; ++index)
39     {
40         printf("%d    ", Array[index]);
41     }
42     return 0;
43 }

 

希尔排序

标签:***   stdio.h   好的   class   color   std   pre   blog   gap   

原文地址:http://www.cnblogs.com/liuteng/p/6444757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!