各种排序算法的C实现

各种排序算法的C实现

ID:37717959

大小:25.94 KB

页数:7页

时间:2019-05-29

各种排序算法的C实现_第1页
各种排序算法的C实现_第2页
各种排序算法的C实现_第3页
各种排序算法的C实现_第4页
各种排序算法的C实现_第5页
资源描述:

《各种排序算法的C实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、各种排序算法的C++实现本程序实现数据结构中的常用排序算法,用标准C++函数模板编写,不依赖于任何平台和任何项目,已经在Codeblocks10.05(GCC4.5.1)和VS2010平台上测试通过。01/*****************************************************************************02*sort.h03*04*Somesortalgorithms.05*06*Thisfileincludesseveralusuallyusedsortingalgorithm,suchas:bub

2、ble07*sorting,selectionsorting,insertionsorting,quicksorting,merging08*sorting,andheapsorting.09*10*ZhangMing,2010-07,Xi'anJiaotongUniversity.11*****************************************************************************/121314#ifndefSORT_H15#defineSORT_H161718#include192

3、021usingnamespacestd;222324namespaceitlab25{2627templatevoidbubbleSort(vector&,int,int);28templatevoidselectSort(vector&,int,int);29templatevoidinsertSort(vector&,int,int);30templatevoidquickSort(vector

4、>&,int,int);31templatevoidmergSort(vector&,int,int);32templatevoidheapSort(vector&,int,int);3334templateconstType&median3(vector&,int,int);35templatevoidmerg(vector&,int,int,int,int);36template

5、eType>voidfilterDown(vector&,int,int);373839#include4041}42//namespaceitlab434445#endif46//SORT_H001/*****************************************************************************002*sort-impl.h004*Implementationforsortalgorithms.007******************************

6、***********************************************/010/**011*Bubblesortalgorithm.//012*"a"---->arrayofComparableitems.013*"left"---->theleft-mostindexofthesubarray.014*"right"---->theright-mostindexofthesubarray.015*/016template017voidbubbleSort(vector&a,intleft,i

7、ntright)018{019boolcond;020for(inti=left;ii;--j)024if(a[j]arrayofComparableitems.039*"left"---->thele

8、ft-mostindexofthesubarray.040*"ri

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。