严蔚敏 数据结构第十章 内部排序的具体代码(c++,附测试数据)(Yan Yumin data structure of the tenth chapter of the internal sorting of the specific code (c++, attached to test data)).doc

严蔚敏 数据结构第十章 内部排序的具体代码(c++,附测试数据)(Yan Yumin data structure of the tenth chapter of the internal sorting of the specific code (c++, attached to test data)).doc

  1. 1、本文档共23页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
严蔚敏数据结构第十章内部排序的具体代码(c,附测试数据)(YanYumindatastructureofthetenthchapteroftheinternalsortingofthespecificcode(c,attachedtotestdata))

严蔚敏 数据结构第十章 内部排序的具体代码(c++,附测试数据)(Yan Yumin data structure of the tenth chapter of the internal sorting of the specific code (c++, attached to test data)) Test data: / * generated EXE file, directly to the test data can be pasted into the DOS window! Ten 32 1187653245782036, 2894 32 1187653245782036, 2894 1187653245782036, 2894 Ten 32 1187653245782036, 2894 Thirty-six * / #includeiostream #define MAXSIZE / / 20 order table length #define LT (a, b) (a b) #define EQ (a, b) (a = b) #define LQ (a, b) (a b) Using namespace std; Typedef int KeyType; / / keyword in this chapter are as integer Typedef char* InfoType; Typedef struct { KeyType key; InfoType otherinfo; }RedType; / / record type Typedef struct { RedType r[MAXSIZE+1]; unit //0 used as sentry Int length; }SqList; / / the order of the table type //******************************************* / / direct insertion sort Void InsertSort (SqList, L) { / / sorted in non descending order from the table, after the forward sequence comparison Int, I, j; For (I = 2; I L.length; + + I) If LT (L.r[i].key, L.r[i-1].key) { L.r[0]=L.r[i]; For (J = I-1; LT (L.r[0].key, L.r[j].key); --j) L.r[j+1]=L.r[j]; L.r[j+1]=L.r[0]; }//if } //*********************** / / binary insertion sort Void BInsertSort (SqList, L) { Int, I, j; Int, high, low, m; For (i=2; i=L.length; ++i) { L.r[0]=L.r[i]; Low=1; high=i-1; / / search range from 1 to I-1 While (low=high) { M= (low+high) /2; If LT (L.r[0].key, L.r[m].key) high=m-1; Else low=m+1; / / to find the number of L.r[0].key =L.r[m].key, which is different with the binary search. Its also the reason why high+1 is taken underneath }//while bisearch For (j=i-1; j=high+1; --j) L.r[j+1]=L.r[j]; After the end of high+1 / / bisearch position for insertion position L.r[high+1]=L.r[0]; }//for }//BInsertSort //********************************* Typedef int SortData; Void Swap (SortData, a, SortData, b) { SortData temp; Temp=a; A=b; B=temp; } //************************************

您可能关注的文档

文档评论(0)

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

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

版权声明书
用户编号:6111134150000003

1亿VIP精品文档

相关文档