<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>
            C語言

            希爾排序是什么

            時間:2025-03-10 12:23:32 C語言 我要投稿
            • 相關推薦

            希爾排序是什么

              希爾排序(shell)是對插入排序的一個改裝,它每次排序把序列的元素按照某個增量分成幾個子序列,對這幾個子序列進行插入排序,然后不斷的縮小增量擴大每個子序列的元素數量,直到增量為一的時候子序列就和原先的待排列序列一樣了,此時只需要做少量的比較和移動就可以完成對序列的排序了.以下是小編為大家搜索整理的希爾排序是什么,希望能給大家帶來幫助!更多精彩內容請持續關注我們應屆畢業生考試網!

              [cpp] view plaincopy

              #include ;

              void Shell_Sort(int a[], int n)

              {

              int h,i,j,temp;

              for (h=n/2; h>0; h=h/2)

              {

              for (i=h; i

              {

              temp = a[i];

              for (j=i-h; j>=0 && temp < a[j]; j-=h)

              {

              a[j+h] = a[j];

              }

              a[j+h] = temp;

              }

              }

              }

              int main(void)

              {

              int arr[]={1,5,2,4,3,8,6,7,9};

              int count=sizeof(arr)/sizeof(int);

              Shell_Sort(arr,count);

              int k;

              for(k=0;k

              {

              printf("%d",arr[k]);

              }

              return 0;

              }

              PHP版本

              [php] view plaincopy

              $arr=array(1,5,2,4,3,8,6,7,9);

              print "排序前 ";

              print_r($arr);

              echo "

              ";

              $arr=shell_sort($arr);

              print "排序后 ";

              print_r($arr);

              function shell_sort($array)

              {

              $count = count($array);

              for ($h=intval($count/2); $h>0; $h=intval($h/2))

              {

              for ($i=$h; $i<$count; $i++)

              {

              $temp = $array[$i];

              for ($j=$i-$h; $j>=0 && $temp < $array[$j]; $j-=$h)

              {

              $array[$j+$h] = $array[$j];

              }

              $array[$j+$h] = $temp;

              }

              }

              return $array;

              }

              ?>

            【希爾排序是什么】相關文章:

            希爾排序(C語言實現)09-06

            希爾排序算法的C語言實現示例08-30

            內部排序之堆排序的實現09-15

            Excel對表格內容自定義排序的步驟是什么10-26

            C#排序算法之快速排序09-09

            C#排序算法之堆排序07-21

            C++ 排序插入排序詳解08-03

            c語言中冒泡排序、插入排序、選擇排序算法比較07-11

            PHP數組的排序09-28

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看