zoukankan      html  css  js  c++  java
  • 希尔排序

    希尔排序

     1 //对每列元素进行插入排序
     2 void sortInterval(int *arr, int beg, int increment, int len)
     3 {
     4     int first_unsorted;//第一个未排序的元素
     5     int current;//暂存待插入的元素
     6     int move;//工作指针
     7 
     8     for(first_unsorted = beg+increment; first_unsorted < len; first_unsorted += increment)
     9         if(arr[first_unsorted] < arr[first_unsorted-increment])
    10         {
    11             current = arr[first_unsorted];
    12             move = first_unsorted;
    13             do{
    14                 arr[move] = arr[move-increment];
    15                 move -= increment;
    16             }while(move > 0 && arr[move - increment] > current);
    17             //插入元素
    18             arr[move] = current;
    19         }
    20 }
    21 
    22 //希尔排序
    23 void shellSort(int *arr, int len)
    24 {
    25     int increment;//增量
    26     int beg;//每次插入排序的起始位置
    27 
    28     increment = len;
    29     do{
    30         increment = increment/3 + 1;
    31         //对各列进行插入排序
    32         for(beg = 0; beg < increment; beg++)
    33             sortInterval(arr,beg,increment,len);
    34     }while(increment > 1);
    35 }
  • 相关阅读:
    jsp 页面获取当前路径
    html5 页面音频
    微信关于网页授权access_token和普通access_token的区别
    Texlive source
    vscode 快捷键
    vscode setting
    vscode extension 插件管理
    what
    linux manual
    java tool type
  • 原文地址:https://www.cnblogs.com/cpsmile/p/4423266.html
Copyright © 2011-2022 走看看