0001 #include <time.h> 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 NULL != A 0015 srand ( ( unsigned int ) time ( NULL ) ); 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 }