/* selection sort sort_select.c */ #include /* Macro definition */ #define NUM 10 int main() { /**** (1) variable declaration ****/ int A[NUM] = {8,2,7,4,5,6,9,0,1,3}; int i, j, temp; /**** (2) processing contents ****/ /* display array before sorting */ printf("Array before sorting: \n"); for (i=0;i"); } if (k == smallest_index ) { printf("!"); } printf("%d ", A[k]); // Insert new line if k reaches the end of the array if (k == NUM - 1) { printf("\n"); } } // If compared number is smaller than current smallest number, // make it the new smallest if (A[j] < A[smallest_index]) { smallest_index = j; } } // At the end of the search, swap smallest with element to replace if (i != smallest_index) { temp = A[i]; A[i] = A[smallest_index]; A[smallest_index] = temp; swaps++; } printf("\n"); } /* display array after sorting */ printf("Sorted array: \n"); for (i=0;i