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/DataStructure/Code/ex04/ex4.cpp

91 lines
2.5 KiB
C++
Raw Normal View History

2021-10-21 12:30:17 +00:00
#include <stdio.h>
#include <stdlib.h>
2021-10-29 08:51:54 +00:00
#include "vec.h"
2021-10-21 12:30:17 +00:00
int main()
{
int flag = 0;
int temp[5];
2021-10-28 12:48:14 +00:00
clock_t astart_t, aend_t, a_start_t, a_end_t;
2021-10-21 12:30:17 +00:00
2021-10-28 12:48:14 +00:00
clock_t bstart_t, bend_t, b_start_t, b_end_t;
2021-10-21 12:30:17 +00:00
srand(time(NULL));
int len;
2022-02-10 08:09:15 +00:00
printf("输入秩\n");
2021-10-21 12:30:17 +00:00
scanf("%d", &len);
2022-02-10 08:09:15 +00:00
printf("生成数组\n");
2021-10-21 12:30:17 +00:00
// scanf("%d", &len);
2021-10-28 12:48:14 +00:00
Vec a(len, 1);
Vec b(len, 2);
Vec a_(&a);
Vec b_(&b);
2022-02-10 08:09:15 +00:00
printf("A归并排序...\n");
2021-10-21 12:30:17 +00:00
2021-10-28 12:48:14 +00:00
astart_t = clock();
a.mergeSort(0, a.getused());
aend_t = clock();
2021-10-21 12:30:17 +00:00
2022-02-10 08:09:15 +00:00
printf("A冒泡排序...\n");
2021-10-28 12:48:14 +00:00
a_start_t = clock();
a_.bubbleSort();
a_end_t = clock();
2021-10-21 12:30:17 +00:00
2022-02-10 08:09:15 +00:00
printf("B归并排序...\n");
2021-10-28 12:48:14 +00:00
bstart_t = clock();
b.mergeSort(0, a.getused());
bend_t = clock();
2022-02-10 08:09:15 +00:00
printf("B冒泡排序...\n");
2021-10-28 12:48:14 +00:00
b_start_t = clock();
b_.bubbleSort();
b_end_t = clock();
2022-02-10 08:09:15 +00:00
printf("A归并运算时间: %.4f 秒\n", ((double)(aend_t - astart_t) / CLOCKS_PER_SEC));
printf("A冒泡运算时间: %.4f 秒\n", ((double)(a_end_t - a_start_t) / CLOCKS_PER_SEC));
printf("B归并运算时间: %.4f 秒\n", ((double)(bend_t - bstart_t) / CLOCKS_PER_SEC));
printf("B冒泡运算时间: %.4f 秒\n", ((double)(b_end_t - b_start_t) / CLOCKS_PER_SEC));
2021-10-28 12:48:14 +00:00
2022-02-10 08:09:15 +00:00
printf("输出归并样本A:\n[0-19]\n");
2021-10-28 12:48:14 +00:00
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));
2022-02-10 08:09:15 +00:00
printf("输出冒泡样本A:\n[0-19]\n");
2021-10-28 12:48:14 +00:00
for (int i = 0; i <= 19; i++)
printf("%d\n", a_.get(i));
2021-10-21 12:30:17 +00:00
printf("[50000-50019]\n");
2021-10-28 12:48:14 +00:00
for (int i = 50000; i <= 50019; i++)
printf("%d\n", a_.get(i));
2021-10-21 12:30:17 +00:00
printf("[99980-99999]\n");
2021-10-28 12:48:14 +00:00
for (int i = 99980; i <= 99999; i++)
printf("%d\n", a_.get(i));
2021-10-21 12:30:17 +00:00
2022-02-10 08:09:15 +00:00
printf("输出归并样本B:\n[0-19]\n");
2021-10-28 12:48:14 +00:00
for (int i = 0; i <= 19; i++)
printf("%d\n", b.get(i));
2021-10-21 12:30:17 +00:00
printf("[50000-50019]\n");
2021-10-28 12:48:14 +00:00
for (int i = 50000; i <= 50019; i++)
printf("%d\n", b.get(i));
2021-10-21 12:30:17 +00:00
printf("[99980-99999]\n");
2021-10-28 12:48:14 +00:00
for (int i = 99980; i <= 99999; i++)
printf("%d\n", b.get(i));
2021-10-21 12:30:17 +00:00
2022-02-10 08:09:15 +00:00
printf("输出冒泡样本B:\n[0-19]\n");
2021-10-28 12:48:14 +00:00
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));
2021-10-21 12:30:17 +00:00
system("pause");
}