8640 希尔排序
来源:互联网 发布:淘宝客宣传海报 编辑:程序博客网 时间:2024/05/12 01:22
8640
时间限制:1000MS
题型:编程题
Sample Input10 5 4 8 0 9 3 2 6 7 1
Sample Output
3 2 6 0 1 5 4 8 7 9
1 0 3 2 4 5 6 8 7 9
0 1 2 3 4 5 6 7 8 9
Hint
作者 yqm
答案:
#include<stdio.h>
#include<malloc.h>
#define OK 1
#define ERROR 0
#define ElemType int
typedef struct
{
int *elem;
int length;
}SqList;
int InitList_Sq(SqList &L,int m)
{
L.elem=(ElemType*)malloc((m+1)*sizeof(ElemType));
if(!L.elem)
return ERROR;
L.length=m;
return OK;
}
int Load_Sq(SqList &L)
{
int i;
if(L.length==0)
printf("The List is empty!");
else
{
for(i=1;i<=L.length;i++)
printf("%d ",L.elem[i]);
}
printf("\n");
return OK;
}
void ShellInsert(SqList &L,int dk)
{
int i,j;
for(i=dk+1;i<=L.length;i++)
{
if(L.elem[i]<L.elem[i-dk])
{
L.elem[0]=L.elem[i];
for(j=i-dk;j>0&&L.elem[0]<L.elem[j];j-=dk)
L.elem[j+dk]=L.elem[j];
L.elem[j+dk]=L.elem[0];
}
}
}
void ShellSort(SqList &L,int m)
{
for(m=m/2;m>=1;m=m/2)
{
ShellInsert(L,m);
Load_Sq(L);
}
}
int main()
{
SqList T;
int m,i;
ElemType x;
scanf("%d",&m);
if(InitList_Sq(T,m)) // 判断顺序表是否创建成功
{
for(i=1;i<=m;i++)
{
scanf("%d",&x);
T.elem[i] = x;
}
}
ShellSort(T,m);
return 0;
}
- 8640 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- ZK SpreadSheet PWC2788: setAttribute: Non-serializable attribute with name javax.zkoss.zk.ui.Session
- jQuery数组处理详解
- bzoj 1072: [SCOI2007]排列perm
- 降落伞充气过程仿真(源码)
- Linux 下定时器的实现方式分析
- 8640 希尔排序
- 重复(视频)文件删除软件
- 通过Hibernate4使用SQL Server2008出现org.hibernate.MappingException
- JS控制键盘输入
- 【LeetCode】Path Sum
- 子父页面刷新关闭
- 优盘显示写保护,无法格式化
- POJ 2488 A Knight's Journey
- Codeforces Round #276 (Div. 2)(C)