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

76 lines
1.6 KiB
C++
Raw Normal View History

2021-10-21 12:30:17 +00:00
#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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
scanf("%d", &len);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
// scanf("%d", &len);
Vec a(len,1);
Vec b(len,2);
int amode =0,bmode=0;
printf("<EFBFBD><EFBFBD><EFBFBD>򷽷<EFBFBD> 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<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>: %.4f <20><>\n", ((double)(aend_t - astart_t) / CLOCKS_PER_SEC));
printf("B<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>: %.4f <20><>\n", ((double)(bend_t - bstart_t) / CLOCKS_PER_SEC));
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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");
}