中国科技大学算法导论第一次实验报告Word文件下载.docx

上传人:b****2 文档编号:3205622 上传时间:2023-05-01 格式:DOCX 页数:12 大小:1.18MB
下载 相关 举报
中国科技大学算法导论第一次实验报告Word文件下载.docx_第1页
第1页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第2页
第2页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第3页
第3页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第4页
第4页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第5页
第5页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第6页
第6页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第7页
第7页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第8页
第8页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第9页
第9页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第10页
第10页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第11页
第11页 / 共12页
中国科技大学算法导论第一次实验报告Word文件下载.docx_第12页
第12页 / 共12页
亲,该文档总共12页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

中国科技大学算法导论第一次实验报告Word文件下载.docx

《中国科技大学算法导论第一次实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《中国科技大学算法导论第一次实验报告Word文件下载.docx(12页珍藏版)》请在冰点文库上搜索。

中国科技大学算法导论第一次实验报告Word文件下载.docx

2、算法思想

累加k的值,计算出当k为不同值时算法运行的时间,来算出当k大约为什么值时运行的时间最短,并与传统的快速排序算法的运行时间进行比较。

3、实验结果

输入100个不同的整数值,选取不同的k的值,观察所用时间

4、实验分析

理论上看,k的值选取为20到25较好;

但是,从实际上来看,当k为50左右时间为39毫秒,最少,但不同的时刻运行后的时间都不相同,而且不同的输入时刻的运行时间也不相同,当数据较大时候,对k的值的选取有会有所不同,同时不同性能的机器对测试结果也不同,所以对于k值的选取没有固定的数值。

#include<

iostream>

sys/timeb.h>

usingnamespacestd;

#defineM40

voidswap(int*a,int*b)

{

inttem;

tem=*a;

*a=*b;

*b=tem;

}

intpartition(intv[],constintlow,constinthigh)

inti,pivotpos,pivot;

pivotpos=low;

pivot=v[low];

for(i=low+1;

i<

=high;

++i)

{

if(v[i]<

pivot)

pivotpos++;

if(pivotpos!

=i)swap(v[i],v[pivotpos]);

}

v[low]=v[pivotpos];

v[pivotpos]=pivot;

//cout<

<

"

thepartitionfunctioniscalled\n"

;

returnpivotpos;

/*

voidQuickSort(inta[],constintlow,constinthigh)

intitem;

if(low<

high)

item=partition(a,low,high);

QuickSort(a,low,item-1);

QuickSort(a,item+1,high);

*/

if(high-low<

=M)return;

//cout<

theQuickSortiscalled"

endl;

voidInsertSort(inta[],constintlow,constinthigh)

inti,j;

for(i=1;

high+1;

tem=a[i];

j=i-1;

while(j>

=0&

&

tem<

a[j])

a[j+1]=a[j];

j--;

a[j+1]=tem;

theInsertSortiscalled"

voidHybridSort(inta[],constintlow,constinthigh)

QuickSort(a,low,high);

InsertSort(a,low,high);

cout<

theHybidSortiscalled"

intmain()

inti,a[100];

//int*a=NULL;

longintt;

structtimebt1,t2;

/*cout<

pleaseinputthenumberoftheelement:

cin>

>

n;

a=(int*)malloc(n*sizeof(int));

pleaseinputeveryelement:

*/

for(i=0;

i<

100;

i++)

a[i]=i+10;

//QuickSort(a,0,n-1);

ftime(&

t1);

HybridSort(a,0,99);

aftersortedquickly,theresultis"

for(i=0;

cout<

a[i]<

"

if(i%10==0)cout<

t2);

t=(t2.time-t1.time)*1000+(t2.millitm-t1.millitm);

/*计算时间差*/

printf("

k=%d用时%ld毫秒\n"

M,t);

thememoryofarrayaisfree"

//free(a);

\n"

return0;

----------THEEND,THEREISNOTXTFOLLOWING.------------

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2