[Sort]希尔排序

来源:互联网 发布:高清网络摄像机软件 编辑:程序博客网 时间:2024/06/05 19:33

详细介绍,在本博客的数据结构栏目里有,不过是java版

#include<iostream>using namespace std;void Shell_Sort(int a[],int num){    int d,i,j,c;    for(d = num/2;d>0;d/=2)    {        for(i = d;i<num;i++)        {            if(a[i] < a[i-d])            {                c = a[i];                for(j=i-d;a[j]> c && j>=0;j-=d)                {                    a[j+d] = a[j];                }                a[j+d] = c;            }        }    }}void main(){    int a[] = {57,68,59,52,72,28,96,33,24};    int count = sizeof(a) / sizeof(a[0]);    Shell_Sort(a,count);    for(int i=0;i<count;i++)    {        cout<<a[i]<<" ";    }    cout<<endl;}
0 0
原创粉丝点击