数据结构6种算法排序.doc

数据结构6种算法排序.doc

ID:61484514

大小:121.50 KB

页数:16页

时间:2021-02-04

数据结构6种算法排序.doc_第1页
数据结构6种算法排序.doc_第2页
数据结构6种算法排序.doc_第3页
数据结构6种算法排序.doc_第4页
数据结构6种算法排序.doc_第5页
资源描述:

《数据结构6种算法排序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、排序测试代码:#include#include#include"d_random.h"#include"d_timer.h"usingnamespacestd;//#defineNum5000;templatevoidselectionSort(Tarr[],intn){intsmallIndex;intpass,j;Ttemp;for(pass=0;pass

2、f(arr[j]voidinsertionSort(vector&v){inti,j,n=v.size();Ttemp;for(i=1;i0&&temp

3、-1];j--;}v[j]=temp;}}//templatevoidexchangesort(vector&v){intvsize=v.size(),temp,pass,i;for(pass=0;passv[i+1]){temp=v[pass];v[pass]=v[i+1];v[i+1]=temp;}}voidbubblesort(vector&v){inttemp,n=v.

4、size(),i,j;for(i=1;iv[j+1]){temp=v[j];v[j]=v[j+1];v[j+1]=temp;}}}templateintpivotIndex(vector&v,intfirst,intlast){intmid,scanUp,scanDown;Tpivot,temp;if(first==last)returnlast;elseif(first==last-1)returnfirst;else{

5、mid=(last+first)/2;pivot=v[mid];v[mid]=v[first];v[first]=pivot;scanUp=first+1;scanDown=last-1;while(scanUp

6、p]=v[scanDown];v[scanDown]=temp;}}v[first]=v[scanDown];v[scanDown]=pivot;returnscanDown;}}templatevoidquicksort(vector&v,intfirst,intlast){intpivotLoc;Ttemp;if(last-first<=1)return;elseif(last-first==2){if(v[last-1]

7、-1]=v[first];v[first]=temp;}return;}else{pivotLoc=pivotIndex(v,first,last);quicksort(v,first,pivotLoc);quicksort(v,pivotLoc+1,last);}}templatevoidmerge(vector&v,intfirst,intmid,intlast){vectortempVector;intindexA,indexB,indexV;indexA=first;inde

8、xB=mid;while(indexA

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

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

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