合并排序法时间

归并排序法修改
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <conio.h>
#include <time.h>
const int N=65536*2;
void BottomUpSort(short[],int);
void Merg(short[],int,int,int);
void main()
{
short A[N+1];
srand(time(NULL));
for(int i=1;i<=N;i++)A[i]=rand()%1000;
time_t t1,t2; struct tm pt;
time(&t1);pt=gmtime(&t1);
cout<<setfill(‘0’);
cout<<“排序开始时间:”;
cout<<setw(2)<<(pt->tm_hour+8)%24<<":"<<setw(2)<tm_min<<":"<<setw(2)<tm_sec<<endl;
cout<<“MergeSort排序中”<<flush;
BottomUpSort(A,N);
time(&t2);pt=gmtime(&t2);
cout<<endl<<“排序结束时间:”;
cout<<setw(2)<<(pt->tm_hour+8)%24<<":"<<setw(2)<tm_min<<":"<<setw(2)<tm_sec<<endl;
cout<<“排序耗费时间=”<<t2-t1<<endl;//
getch();
}
void BottomUpSort(short A[],int n)
{
int i,t=1,s;
while(t<n){
cout<<"."<<flush;
s=t;t=2
s;i=0;
……………………………………
// *******************************************************
// * 工 程 名:104合并.dsp *
// * 程 序 名:104合并.cpp *
// * 主要功能:合并排序法时间 *
// * 编制时间:2019年11月21日 *
// ********************************************************

#include
#include <stdlib.h>
#include
#include <conio.h>
#include <time.h>
#define N 655362
using namespace std;
void merge(int A[],int low,int mid,int high)
{
int b[N+1];
int s=low,t=mid+1,k=low;
while(s<=mid&&t<=high)
{
if(A[s]<=A[t])
{
b[k]=A[s];
s++;
}
else
{
b[k]=A[t];
t++;
}
k++;
}
if(s==mid+1)
for(;t<=high;k++,t++)
b[k]=A[t];
else
for(;s<=mid;k++,s++)
b[k]=A[s];
for(int i=low;i<=high;i++)
A[i]=b[i];
}
void Bottomupsort(int A[],int n)
{
int i,t=1,s;
while(t<n)
{
s=t;
t=2
s;
i=0;
while((i+t)<=n)
{
merge(A,i,i+s-1,i+t-1);
i=i+t;
}

	if(i+s-1<n)
	    merge(A,i,i+s-1,n);
	
}
return;

}

int main()
{
int A[N+1];
srand(time(NULL));
for(int i=1;i<=N;i++)A[i]=rand()%1000;
time_t t1,t2; struct tm *pt;
time(&t1);pt=gmtime(&t1);
cout<<setfill(‘0’);
cout<<“排序开始时间:”;
cout<<setw(2)<<(pt->tm_hour+8)%24<<":"<<setw(2)<tm_min<<":"<<setw(2)<tm_sec<<endl;
cout<<“MergeSort排序中”<<flush;
Bottomupsort(A,N);
time(&t2);pt=gmtime(&t2);
cout<<endl<<“排序结束时间:”;

cout<<setw(2)<<(pt->tm_hour+8)%24<<":"<<setw(2)<<pt->tm_min<<":"<<setw(2)<<pt->tm_sec<<endl;
cout<<"排序耗费时间="<<t2-t1<<endl;//
getch();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaaaaayyyy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值