1结构优化

This commit is contained in:
iridiumR 2021-10-05 14:05:19 +08:00
parent 6b64f8a5f2
commit 64eef98057

18
ex1.cpp
View file

@ -5,13 +5,13 @@
int LENGTH; int LENGTH;
//数组长度 //数组长度
bool RANDOM = false; int RANDOM = 0;
//是否随机生成数组 //是否随机生成数组
int MODE = 0; int MODE = 0;
//MODE_1: µü´ú //1: 迭代
//MODE_2: µÝ¹é //2: 递归
#define OUTPUT // #define OUTPUT
//是否输出 //是否输出
int *a; int *a;
@ -65,7 +65,7 @@ void bobblesort1B(int a[], int n)
bobblesort1B(a, n); bobblesort1B(a, n);
} }
void (*bobblesort1C)(int a[], int n); void (*bobblesort)(int a[], int n);
void init() void init()
{ {
@ -79,14 +79,16 @@ void init()
a[i] = LENGTH - i; a[i] = LENGTH - i;
if (MODE == 1) if (MODE == 1)
bobblesort1C = bobblesort1A; bobblesort = bobblesort1A;
else if (MODE == 2) else if (MODE == 2)
bobblesort1C = bobblesort1B; bobblesort = bobblesort1B;
} }
int main() int main()
{ {
Begin: Begin:
printf("是否随机生成数组(0/1):");
scanf("%d", &RANDOM);
printf("输入数组长度:"); printf("输入数组长度:");
scanf("%d", &LENGTH); scanf("%d", &LENGTH);
@ -111,7 +113,7 @@ Begin:
#endif #endif
start_t = clock(); start_t = clock();
bobblesort1C(a, LENGTH); bobblesort(a, LENGTH);
end_t = clock(); end_t = clock();
#ifdef OUTPUT #ifdef OUTPUT