- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
排序算法模板实现(Sort algorithm template implementation)
001
# include cstdlib
002
# include iostream
003
004
using namespace std;
005
006
# define selectsort 1
007
# define insertsort 1
008
# define bubblesort 1
009
# define shellsort 1
010
# define quicksort 1
011
# define mergesort 1
012
013
typename template t
014
void print (t array [], int len)
015
{
016
for (int i = 0; i len; i + +) {
017
cout array [in] ;
018
}
019
cout final;
020
}
021
022
typename template t
023
void swap (t a, t b)
024
{
025
t temp = a;
026
a = b;
027
b = temp;
028
}
029
030
# ifdef selectsort
031
typename template t
032
void selectsort (t array [], int len)
033
{
034
int i = 0;
035
int j = 0;
036
int k = - 1;
037
038
for (i = 0; i len; i + +) {
039
k = i;
040
for (j = i + 1; j len; j + +) {
041
if (array [j] array [k]) {
042
k = j;
043
}
044
}
045
046
if (k! = i) {
047
swap (array array [in], [k]);
048
}
049
}
050
}
051
# endif
052
053
# ifdef insertsort
054
typename template t
055
void insertsort (t array [], int len)
056
{
057
int i = 0;
058
int j = 0;
059
int k = - 1;
060
int temp = - 1;
061
062
for (i = 1; in len; i + +) {
063
k = i;
064
temp = array [c];
065
066
for (j = - 1; (j = 0) (array [j] temp); j) {
067
array [j + 1] = array [j];
068
k = j;
069
}
070
071
array [k] = temp;
072
}
073
}
074
# endif
075
076
# ifdef bubblesort
077
typename template t
078
void bubblesort (t array [], int len)
079
{
080
int i = 0;
081
int j = 0;
082
int exchange = 1;
083
084
for (i = 0; i len exchange; i + +) {
085
exchange = 0;
086
for (j = len - 1; j 0;
j) {
087
if (array [j] array (j - 1) {
088
swap (array array [j] [j-1]).
089
exchange = 1;
090
}
091
}
092
}
093
}
094
# endif
095
096
# ifdef shellsort
typename template t
098
void shellsort (t array [], int len)
099
{
100
int i = 0;
101
int i = 0;
102
int k = 0.
103
int temp = 0.
(gap = len.
do {
gap: gap / 3 + 1.
for (i = gap; i len; i = (map)
k = 1.
temp = array [k].
for (i = (i - gap; i = 0 array [j] years; j
您可能关注的文档
- 《因数中间或末尾有零的乘法》案例分析(Case analysis of multiplication of zero in the middle of a factor or at the end).doc
- 《游戏的封包、资源和提取器》简介(Brief introduction of game, and packet resource extractor).doc
- 《圆的周长》导学案(The guide to the circumference of a circle).doc
- 《月光下的凤尾竹》创作背景及演奏技巧&方法讲解(In the background of Moonlight creation and performance skills & methods of explanation).doc
- 《圆柱的表面积》教学设计(Teaching design of surface area of cylinder).doc
- 《战火兄弟连之地狱公路》游戏流程全攻略(Fire brothers even hell highway game process Raiders).doc
- 《哲学与人生》期末试卷及答案(Final papers and answers to Philosophy and life).doc
- 《张惠妹2010阿密特世界巡回演唱会》(Sherry 2010 live world tour).doc
- 《真三国无双4》存档修改攻略(Real Three Kingdoms 4 archive modification strategy).doc
- 《整蛊邻居》游戏攻略(Neighbors tricky games).doc
- 高考英语一轮复习 板块1 教材复习 Book 8 Unit 5 Meeting your ancestors.pptx
- 新高考英语读后续写名校试题及写作素材 读后续写Writing 4(13张).pptx
- 高考英语一轮复习 板块1 教材复习 Book 8 Unit 2 Cloning.pptx
- 高考英语一轮复习 板块1 教材复习 Book 6 Unit 3 A healthy life.pptx
- 高考英语一轮复习 板块1 教材复习 Book 8 Unit 1 A land of diversity.pptx
- 高考英语一轮复习 板块1 教材复习 Book 6 Unit 4 Global warming.pptx
- 高考英语一轮复习 板块1 教材复习 Book 7 Unit 5 Travelling abroad.pptx
- 高考英语一轮复习 板块1 教材复习 Book 8 Unit 3 Inventors and inventions.pptx
- 英文SCI论文写作时的语言表达技巧.doc
- 科技英语论文报告写作.ppt
最近下载
- 日语动词分类及变化形式讲解.pptx VIP
- 公司组织架构图.xlsx VIP
- WST 403-2024 临床化学检验常用项目分析质量标准.pdf VIP
- 江南地区的开发()解说.ppt VIP
- 《ISO 37001-2025 反贿赂管理体系要求及使用指南》专业解读和应用培训指导材料之1:2范围+3术语和定义(雷泽佳编制-2025A0).pdf VIP
- 高速公路边线放样及勘测定界测量方案.pdf VIP
- 不动产登记代理人职业资格考试.docx VIP
- 人教版五年级上册数学第八单元《总复习》全单元教学课件(新插图).pptx VIP
- 建筑工程材料性能检测(中职):混凝土性能检测PPT教学课件.pptx
- 护士长年终述职报告PPT模板(含完整内容).pptx VIP
原创力文档


文档评论(0)