From 978af22a7abace14746e1d609aa47cf2dfd844f7 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Thu, 21 Oct 2021 20:30:17 +0800 Subject: [PATCH] 4 --- ex4/ex4.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ex4/ex4.cpp diff --git a/ex4/ex4.cpp b/ex4/ex4.cpp new file mode 100644 index 0000000..7f9825e --- /dev/null +++ b/ex4/ex4.cpp @@ -0,0 +1,75 @@ +#include +#include +#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"); +}