文档介绍:.
1、方案设计:
我这次实验通过随机生成30000个随机数,把随机数存到数组中,用这同一组随机数据分别进行四种排序,直接插入排序、直接选择排序、冒泡排序和快速排序。还通过了调用txt文件把运算所需时间导岀,分别输岀各个算法所需用时并对: .
1、方案设计:
我这次实验通过随机生成30000个随机数,把随机数存到数组中,用这同一组随机数据分别进行四种排序,直接插入排序、直接选择排序、冒泡排序和快速排序。还通过了调用txt文件把运算所需时间导岀,分别输岀各个算法所需用时并对用时时长再进行冒泡排序算岀用时最短的算法。
2、程序代码:
^defineN30000voidWrong()ow=0;
st[top].high二rr~l;
while(top>~l)
{low=st[top].low;high二st[top].high;top—;i=low;j=high;if(low<high){temp=a[low];while(i!=j){while(i<j&&a[j]>temp)j--;if(i<j){a[i]二a[j];i++;}while(i<j&&a[i]<temp)i++;辻(i<j){a[j]=a[i];j—;}}aLi]-temp;top++;st[top].low二low;st[top].high=i~l;top++;st[top].low二i+1;st[top].high二high;zV);
for(i=0;i<N;i++)fprintf(fp,"%d:b[i]);
fclose(fp);return(time);doubleTSelectSort(inta[],intpmfor(i=0;i<N;i++)fprintf(fp,"%d",b[i]);fclose(fp);return(time);doubleTBubbleSort(inta[],intfor(i=0;i<N;i++)
fprintf(fp,"%d",b[i]);fclose(fp);return(time);doubleTquicksort(inta[],intn,intp)xt〃,〃w〃);for(i=0;i<N;i++)fprintf(fp,"%d",b[i]);fclose(fp);return(time);voidBubleSort(doublea[])xt",〃w");for(i=0;i<N;i++)fprintf(fp,〃%dfclose(fp);getchar();printfC\ngetchar();break;case2:请按任意键继续”);TInsertSort(a,p);printfC\n请按任意键继
续〃);getchar();break;case3:TSelectSort(a,p);printf("\ngetchar();break;请按任意键继续〃);case4:
TBubbleSort(a,p);printf(,z\n请按任意键继续!");getchar();break;case5:Tquicksort(a,N,p);printf(,z\n请按任意键继续!");getchar();b