shell排序问题??大家来解释一下。谢了。

iceadf 2003-08-24 01:10:06

#include<stdio.h>
void shell(int e[],int n)
{
int j,k,h,y;
for(h=n/2; h>0; h=h/2)
{
for(j=h; j<n; j++){
y=e[j];
for(k=j-h; k>=0&&y<e[k];k-=h)
e[k+h]=e[k];
e[k+h]=y;
}
}
}
void main()
{
int i;
int a[9]={2,6,1,4,8,7,0,9,14};
shell(a,9);
for(i=0;i<9;i++)
printf("%4d",a[i]);
printf("\n");
getch();
}

...全文
37 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
影子传说 2003-08-26
  • 打赏
  • 举报
回复
也许要搞本数据结构的书看看
wangmin_yjitx 2003-08-25
  • 打赏
  • 举报
回复
不就是跳步的直插排序
iceadf 2003-08-25
  • 打赏
  • 举报
回复
是呀这个程序。始终看不懂。大家帮忙解释一下。 看懂了马上结帐。谢了。
aifudi 2003-08-24
  • 打赏
  • 举报
回复
解释什么啊??

shell算法吗???
lyff8neo 2003-08-24
  • 打赏
  • 举报
回复
有什么问题啊?没有说清楚题目啊!!!!
书上说的详细一些啊!
iceadf 2003-08-24
  • 打赏
  • 举报
回复
大家帮个忙呀。
目 录 摘 要 1 前 言 2 正 文 3 1. 采用类C语言定义相关的数据类型 4 2. 各模块的伪码算法 5 3. 函数的调用关系图 11 4. 调试分析 11 5. 测试结果 13 6. 源程序(带注释) 16 总 结 28 参考文献 29 致 30 附件Ⅰ 部分源程序代码 31 摘要 排序是计算机程序设计中的一种重要操作。各种部排序算法的时间复杂度分析结果只给出了算法执行时间的阶,或大概执行时间。 关键字:排序,性能分析。 前 言 排序是计算机程序设计中的一种重要操作。它的功能是将一个数据元素的任意序列,重新排列成一个按关键字有序的序列。内部排序的方法很多,但是就其全面性能而言,很难 提出一种被认为是最好的方法,每一种方法都有各自的优缺点,适合在不同的环境下使用。如果按排序过程中依据的不同原则对内部排序方法进行分类,则大致可分为插入排序,交换排序,选择排序,归并排序和记数排序等五类。 这几种排序算法是在顺序存储结构上实现的,因此在排序过程中需要进行大量记录的移动。当记录很大时,时间耗费很大,此时可采用静态链表作存储结构。但是有的排序方法,无法实现表排序。在这种情况下可以进行地址排序,即另设一个地址向量指示相应记录。 正文 1. 采用类c语言定义相关的数据类型 Int整型, char字符型, 2. 各模块的伪码算法 (1) 插入排序伪码算法: Void InsertSort(Splist&L){ For(i=2;i<=L.length;++i) If(LT(L.r[i].key,L.r[i-1].key))  //“《”,须将L.r[i]插入有序子表 { L.r[0]= L.r[i];         //复制为哨兵 L.r[i]= L.r[i-1]; For(j)i-2;LT(L.r[0].key,L.r[j].key);--j) L.r[j+1]= L.r[j];         //记录后移 L.r[j+1]= L.r[0]; //插入到正确位置 } }//InsertSort (2) 希尔排序 Void shllInsert(Splist & L,int dk){ For(i=dk+1;i<=L.length;++i) If(LT(L.r[i].key,L.r[i-dk].key)) { L.r[0]= L.r[i];           //暂存 For(j=i-dk;j>0&<(L.r0].key,L.r[j].key);j-=dk) L.r[j+dk]=L.r[j];       //记录后移 L.r[j+dk]=L.r[0];} //插入 }//shellsort Void shllsort (Splist & L,int data[],int t){ For(k=0;k
#include #include #include #define Maxsize 100 typedef struct { int jchk; int zhyk; int xxk; int shyk; int rwk; }Lesson; typedef struct { char name[10]; char sex[4]; char clas[10]; char mayor[20]; char number[20]; Lesson kch; }Linelist; typedef struct { Linelist data[Maxsize]; int length; }Sqlist; FILE *fp; /*保存函数*/ void Save(Sqlist &L,int n) { int i=0; system("cls"); if((fp=fopen("Sqlist.txt","w"))==NULL) { printf("文件打不开!\n"); exit(1); } while(i=50 && L.data[i].kch.zhyk>=50 && L.data[i].kch.xxk>=24 && L.data[i].kch.shyk>=20 && L.data[i].kch.rwk>=8) { printf("\n姓名 性别 班级 专业 学号\n"); printf("%s %15s %15s %15s %15s",L.data[i].name,L.data[i].sex, L.data[i].clas,L.data[i].mayor,L.data[i].number); printf("\n"); printf("基础课 专业课 选修课 实验课 人文课(学分)\n"); printf("%d %15d %15d %15d %15d\n", L.data[i].kch.jchk,L.data[i].kch.zhyk,L.data[i].kch.xxk, L.data[i].kch.shyk,L.data[i].kch.rwk); found=1; } if(found==0) printf("\n\n\n\n\n\n\t\t\t所有学生均不达到标准,不能毕业!\n"); system("pause"); } /*统计未毕业学生*/ void Diseducate(Sqlist L,int n) { int i,found=0; system("cls"); for(i=0;i=0 && strcmp(temp.number,L.data[j].number)<0) { L.data[j+1]=L.data[j]; j--; } L.data[j+1]=temp; } printf("请输入学生学号:\n"); scanf("%s",k); printf("\n"); while(low<=high) { mid=(low+high)/2; if(strcmp(k,L.data[mid].number)==0) { printf("该学生信息如下:\n"); printf("\n\n姓名 性别 班级 专业 学号\n"); printf("%s %15s %15s %15s %15s",L.data[mid].name,L.data[mid].sex, L.data[mid].clas,L.data[mid].mayor,L.data[mid].number); printf("\n基础课 专业课 选修课 实验课 人文课\n"); printf("%d %15d %15d %15d %15d\n",L.data[mid].kch.jchk,L.data[mid].kch.zhyk, L.data[mid].kch.xxk,L.data[mid].kch.shyk,L.data[mid].kch.rwk); return (mid); } else if(strcmp(k,L.data[mid].number)<0) high=mid-1; else low=mid+1; } printf("未找到!\n"); return -1; } /*删除*/ void Delelem(Sqlist &L,int &n) { int i,j;char J; i=Binsearch(L,n); if(i==-1) printf("未找到!\n"); else { for(j=i;j0) { for(i=gap;i=0 && temp.kch.jchk0) { for(i=gap;i=0 && temp.kch.zhyk0) { for(i=gap;i=0 && temp.kch.xxk0) { for(i=gap;i=0 && temp.kch.shyk0) { for(i=gap;i=0 && temp.kch.rwk 使 用 本 系 统 !\n"); printf("\n\n\n\n\t\t\t Please input anykey to quit!!\n\a\a");m=5;break; default: printf("\t\t\t Error!\n"); printf("\t\t\t please input again!:"); scanf("%d",&c);break; } } } /*主函数*/ void main() { int i,j=123;char ch;system("color 97"); printf("\t==============================================================\n"); printf("\t\t\t\t系 统 公告!\n"); printf("\t==============================================================\n"); printf("\n\t1、本系统是学分管理程序系统,首先要输入密码才能进入系统!"); printf("\n\n\t2、进入系统后请按提示操作!"); printf("\n\n\t3、注意:系统中要输入的课程均是汉语拼音!"); printf("\n\n\t4、基础课 专业课 选修课 实验课 人文课分别如下: "); printf("\n\n\t5、jchk zhyk xxk shyk rwk"); printf("\n\n\t6、本系统制作者 : 李仁刚 舒世朝 李俊宏"); printf("\n\n\t7、 E_mail : ahhqlrg@163.com\t手机:13516474749"); printf("\n\n\t8、 Made By VC6.0++\t\t\t 2009年12月14日\n"); printf("\n\t============================================================\n"); printf("\t欢迎使用学分管理系统!\n\n"); printf("\t请输入密码(123):"); scanf("%d",&i); int m=1; Sqlist L; Initlist(L); system("color 3e"); do { if(i==j) { system("cls"); printf("是否打开原有文件(y or n)?"); scanf("%s",&ch); if(ch=='y') { L.length=Open(L); menu(L,L.length,m); } else menu(L,L.length,m); } else { printf("密码错误!\n"); printf("please input again!"); scanf("%d",&i); } }while(m==1); }

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧