1) What does the following code do? 2) What changes would you make to improve the code (not regarding performance)? void func(int array[ARRAY_SIZE]) { int p = 0; for (int r = 0; r < 4; r++) { for (int i = p; i < ARRAY_SIZE; i++) { if (array[i] % 5 == r) { if (i != p) { int temp = array[p]; array[p] = array[i]; array[i] = temp; } p++; } } } }
Anónimo
1) Sort the array according to the remainder from division by 5. 2) - Change "5" with a function parameter e.g. "rem". - Change "4" to "rem - 1" - Make the array size a function parameter. - User a more meaningful function name. - Add comments.