From 64eef98057427d58094084a2d83372e53e2bc9b3 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Tue, 5 Oct 2021 14:05:19 +0800 Subject: [PATCH] =?UTF-8?q?1=E7=BB=93=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex1.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ex1.cpp b/ex1.cpp index 32e37aa..bb05dcf 100644 --- a/ex1.cpp +++ b/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