c语言版数据结构希尔排序.docx

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
2. 希尔排序 详细设计 #include stdio.h #include stdlib.h #include time.h typedef int KeyType; typedef int OtherType; #define Max_Size 5000 typedef struct { KeyType key; OtherType other_data; }RecordType; void ShellInsert(RecordType r[], int length, int delta) /* 对记录数组 r 做一趟希尔插入排序, length 为数组的长度 ,delta 为增量 */ { int i,j; for(i=1+delta;i=length;i=i+delta) //1+delta 为第一个子序列的第二个元素的下标 if(r[i].keyr[i-delta].key) { RecordType t; t=r[i]; // 备份 r[i] for(j=i;j0 t.keyr[j-delta].key;j-=delta) r[j]=r[j-delta]; r[j]=t; } }/*ShellInsert*/ void ShellSort(RecordType r[], int length, int delta[], int n) /* 对记录数组 r 做希尔排序, length 为数组 r 的长度, delta 为增量数组, n 为 delta[] 的 长度 */ { for(int i=0;in;++i) ShellInsert(r,length,delta[i]); } void main() { int i; RecordType r[Max_Size]; int len; int delta[4]={6,4,2,1}; printf(” 请输入待排序记录的长度:”); sca nf(%d,len); sran d(( un sig ned)time(NULL)); for(i=1;i=le n;i++) r[i].key =ran d(); printf(\n 待排序记录:\n); for(i=1;i=le n;i++) prin tf(%6d ”,r[i].key); prin tf(\n); ShellSort(r,le n, delta,4); printf(\n 排序后的记录:\n); for(i=1;i=le n;i++) prin tf(%6d ”,r[i].key); prin tf(\n\n); } 测试结果 C:\Use rs\ 1\De skto p筒倨结构课卡呈设计\希尔\ Deb ug\希尔exe 请输入待排序记录的长度:药 待排序记录: 29511 1H193 2517 2SS08 16330 2982 313 16107 28172 28 27742 排序后的记录: E28 2G46T 313 1G98G 2517 23224 2982 2496 7 27742 5190 2781G Press any to continue, 539 28172 16057 2322M

文档评论(0)

xiaozu + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档