diff --git a/ex2.1/bubble_sort_int.cpp b/ex2.1/bubble_sort_int.cpp index 0c83ce5..077ec29 100644 --- a/ex2.1/bubble_sort_int.cpp +++ b/ex2.1/bubble_sort_int.cpp @@ -83,8 +83,8 @@ void orderptr( int* a, int* b ) { return; } - int* tmp = a; - a = b; - b = tmp; + int tmp = *a; + *a = *b; + *b = tmp; } #endif diff --git a/ex2.1/bubble_sort_str.cpp b/ex2.1/bubble_sort_str.cpp index b6b700a..d4b5884 100644 --- a/ex2.1/bubble_sort_str.cpp +++ b/ex2.1/bubble_sort_str.cpp @@ -15,9 +15,9 @@ void sort( const char** A, const int size ); #if !USE_PTR -void order( const char* a, const char* b ); +void order( const char* &a, const char* &b ); #else -void orderptr( const char* &a, const char* &b ); +void orderptr( const char* *a, const char* *b ); #endif @@ -78,34 +78,14 @@ void sort( const char** A, const int size ) { #if !USE_PTR order( A[ i ], A[ j ] ); #else - orderptr( A[ i ], A[ j ] ); + orderptr( &A[ i ], &A[ j ] ); #endif } } } #if !USE_PTR -void order( const char* a, const char* b ) { - #if VERBOSE - std::cout << "Order: " << a << std::endl; - #endif - // b is greater or equal to a, do nothing - if ( strcmp(a, b) > 0) { - #if VERBOSE - std::cout << "Ordering OK" << std::endl; - #endif - return; - } - #if VERBOSE - std::cout << "Ordering ToDo" << std::endl; - #endif - - const char* tmp = a; - a = b; - b = tmp; -} -#else -void orderptr( const char* &a, const char* &b ) { +void order( const char* &a, const char* &b ) { #if VERBOSE std::cout << "Order: " << a << ", " << b << std::endl; #endif @@ -123,4 +103,24 @@ void orderptr( const char* &a, const char* &b ) { a = b; b = tmp; } +#else +void orderptr( const char* *a, const char* *b ) { + #if VERBOSE + std::cout << "Order: " << a << std::endl; + #endif + // b is greater or equal to a, do nothing + if ( strcmp(*a, *b) > 0) { + #if VERBOSE + std::cout << "Ordering OK" << std::endl; + #endif + return; + } + #if VERBOSE + std::cout << "Ordering ToDo" << std::endl; + #endif + + const char* tmp = *a; + *a = *b; + *b = tmp; +} #endif