C语言 百分网手机站

希尔排序是什么

时间:2020-10-31 16:43:22 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;

  }

  ?>

【希尔排序是什么】相关文章:

1.希尔排序(C语言实现)

2.希尔排序算法的C语言实现示例

3.C++ 排序插入排序详解

4.c语言中冒泡排序、插入排序、选择排序算法比较

5.PHP数组的排序

6.java的常见排序方法

7.excel2010如何排序

8.Excel表格怎么自动排序

9.PHP排序算法类讲解