Shell
来源:互联网 发布:照片管理的软件 编辑:程序博客网 时间:2024/06/06 01:07
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 1000
int shell(int a[],int n)
{
int j, gap;
for (gap = n/2; gap > 0; gap /= 2)
for (j = gap; j < n; j++)
if (a[j] < a[j - gap])
{
int temp = a[j];
int k = j - gap;
while (k >= 0 && a[k] > temp)
{
a[k + gap] = a[k];
k -= gap;
}
a[k + gap] = temp;
}
}
int main()
{
int a[N],i;
memset(a,0,sizeof(a));
srand((unsigned int)time(NULL));
for(i=0;i<N;i++)
a[i]=rand()%100+1;
shell(a,N);
for(i=0;i<N;i++)
printf("%d ",a[i]);
#include<string.h>
#include<stdlib.h>
#define N 1000
int shell(int a[],int n)
{
int j, gap;
for (gap = n/2; gap > 0; gap /= 2)
for (j = gap; j < n; j++)
if (a[j] < a[j - gap])
{
int temp = a[j];
int k = j - gap;
while (k >= 0 && a[k] > temp)
{
a[k + gap] = a[k];
k -= gap;
}
a[k + gap] = temp;
}
}
int main()
{
int a[N],i;
memset(a,0,sizeof(a));
srand((unsigned int)time(NULL));
for(i=0;i<N;i++)
a[i]=rand()%100+1;
shell(a,N);
for(i=0;i<N;i++)
printf("%d ",a[i]);
}
运用了http://blog.csdn.net/morewindows/article/details/6668714/的希尔排序
阅读全文
0 0
- shell
- shell
- shell
- shell
- shell
- Shell
- shell
- Shell
- shell
- shell
- SHELL
- Shell
- shell
- shell
- shell
- shell
- shell
- shell
- 常用工具类 作业
- API学习java.lang.Object.notify
- 1107. Social Clusters (30) 并查集
- Leetcode 6.ZigZag Conversion
- java中Serializable接口的理解
- Shell
- API学习java.lang.Object.notifyAll
- lintcode -- 两个字符串是变位词
- hadoop学习笔记--13.hive 属性配置、交互式命令行和文件系统交互
- 异步流程控制async
- 数据结构6:斐波那契数列,递归算法,求和算法专题
- 一些知识的总结
- 匿名函数与lambda
- 美团点评2017秋招笔试编程