This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/ex4/ex4.cpp
iridiumR 978af22a7a 4
2021-10-21 20:30:17 +08:00

75 lines
1.6 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include "vec.cpp"
int main()
{
int flag = 0;
int temp[5];
clock_t astart_t, aend_t;
clock_t bstart_t, bend_t;
srand(time(NULL));
int len;
printf("输入秩\n");
scanf("%d", &len);
printf("生成数组\n");
// scanf("%d", &len);
Vec a(len,1);
Vec b(len,2);
int amode =0,bmode=0;
printf("排序方法 1merge 2bubble\n");
scanf("%d %d",&amode,&bmode);
if(amode==1)
{
astart_t = clock();
a.mergeSort(0,a.getused());
aend_t = clock();
}
else if(amode==2)
{
astart_t = clock();
a.bubbleSort();
aend_t = clock();
}
if(bmode==1)
{
bstart_t = clock();
b.mergeSort(0,a.getused());
bend_t = clock();
}
else if(bmode==2)
{
bstart_t = clock();
b.bubbleSort();
bend_t = clock();
}
printf("A运算时间: %.4f 秒\n", ((double)(aend_t - astart_t) / CLOCKS_PER_SEC));
printf("B运算时间: %.4f 秒\n", ((double)(bend_t - bstart_t) / CLOCKS_PER_SEC));
printf("输出样本A:\n[0-19]\n");
for(int i=0;i<=19;i++)
printf("%d\n",a.get(i));
printf("[50000-50019]\n");
for(int i=50000;i<=50019;i++)
printf("%d\n",a.get(i));
printf("[99980-99999]\n");
for(int i=99980;i<=99999;i++)
printf("%d\n",a.get(i));
printf("输出样本B:\n[0-19]\n");
for(int i=0;i<=19;i++)
printf("%d\n",b.get(i));
printf("[50000-50019]\n");
for(int i=50000;i<=50019;i++)
printf("%d\n",b.get(i));
printf("[99980-99999]\n");
for(int i=99980;i<=99999;i++)
printf("%d\n",b.get(i));
system("pause");
}