1结构优化
This commit is contained in:
parent
6b64f8a5f2
commit
64eef98057
1 changed files with 10 additions and 8 deletions
18
ex1.cpp
18
ex1.cpp
|
@ -5,13 +5,13 @@
|
|||
|
||||
int LENGTH;
|
||||
//数组长度
|
||||
bool RANDOM = false;
|
||||
int RANDOM = 0;
|
||||
//是否随机生成数组
|
||||
int MODE = 0;
|
||||
//MODE_1: µü´ú
|
||||
//MODE_2: µÝ¹é
|
||||
//1: 迭代
|
||||
//2: 递归
|
||||
|
||||
#define OUTPUT
|
||||
// #define OUTPUT
|
||||
//是否输出
|
||||
|
||||
int *a;
|
||||
|
@ -65,7 +65,7 @@ void bobblesort1B(int a[], int n)
|
|||
bobblesort1B(a, n);
|
||||
}
|
||||
|
||||
void (*bobblesort1C)(int a[], int n);
|
||||
void (*bobblesort)(int a[], int n);
|
||||
|
||||
void init()
|
||||
{
|
||||
|
@ -79,14 +79,16 @@ void init()
|
|||
a[i] = LENGTH - i;
|
||||
|
||||
if (MODE == 1)
|
||||
bobblesort1C = bobblesort1A;
|
||||
bobblesort = bobblesort1A;
|
||||
else if (MODE == 2)
|
||||
bobblesort1C = bobblesort1B;
|
||||
bobblesort = bobblesort1B;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Begin:
|
||||
printf("是否随机生成数组(0/1):");
|
||||
scanf("%d", &RANDOM);
|
||||
|
||||
printf("输入数组长度:");
|
||||
scanf("%d", &LENGTH);
|
||||
|
@ -111,7 +113,7 @@ Begin:
|
|||
#endif
|
||||
|
||||
start_t = clock();
|
||||
bobblesort1C(a, LENGTH);
|
||||
bobblesort(a, LENGTH);
|
||||
end_t = clock();
|
||||
|
||||
#ifdef OUTPUT
|
||||
|
|
Reference in a new issue