0001 #include <ctime> 0002 #include <iostream> 0003 using namespace std; 0004 #include "random/shuffle.h" 0005 #include "UniPrint/print_int_array.h" 0006 #include "reverse/reverse.h" 0007 #include "sum/sum.h" 0008 0009 /****************************************************************************************** 0010 * ²âÊÔSUM 0011 ******************************************************************************************/ 0012 int main(int argc, char* argv[]) { 0013 int n = (1 < argc) ? atoi(argv[1]) : 7; //ToDo: validate n 0014 int* A = (int*) malloc(n*sizeof(int)); //ToDo: check nullptr != A 0015 srand(31415926); //srand((uint32_t) time(nullptr)); //Ëæ»úÖÖ×Ó 0016 //˳Ðò 0017 for (int i = 0; i < n; i++) A[i] = i; print(A, n); 0018 printf("SumI = %d\n", sumI(A, n)); 0019 printf("SumR1 = %d\n", sum(A, n)); 0020 printf("SumR2 = %d\n\n", sum(A, 0, n)); 0021 //Ëæ»úÖÃÂÒ 0022 shuffle(A, n); print(A, n); 0023 printf("SumI = %d\n", sumI(A, n)); 0024 printf("SumR1 = %d\n", sum(A, n)); 0025 printf("SumR2 = %d\n\n", sum(A, 0, n)); 0026 //ǰºóµßµ¹ 0027 reverse(A, n); print(A, n); 0028 printf("SumI = %d\n", sumI(A, n)); 0029 printf("SumR1 = %d\n", sum(A, n)); 0030 printf("SumR2 = %d\n\n", sum(A, 0, n)); 0031 // 0032 free(A); 0033 printf("Test done.\a\n"); 0034 return 0; 0035 }