/* Lots not complete, but it would not be hard to complete such a skeleton of the */ /* program. This is a "design" or "plan" to make an algorithm work using code */ /* It is preceeded by looking at the problem to be solved and determining a basic */ /* algorithm that would solve it, a set of steps guaranteed to find a solution in */ /* a finite amount of time (actually a very important requirement! */ #define ARRAYSIZE 100 int min_loc(int b[ARRAYSIZE], int k, int n); /* This function will take as input an array of integers, returns an index */ /* Returns index of smallest element in subarray k .. n-1 */ /* Which is a subproblem of the Selection Sort algorithm */ void swap(int b[ARRAYSIZE], int k, int m); /* This simple function swaps elements of the array b "in place" */ /* It swaps the contents of element m with the contents of element k */ void sel_sort(int b[ARRAYSIZE], int n); /* This function takes an array of integers and sorts it into nondecreasing order */ /* It does this by "selecting" the proper value at each step and "swapping" it */ /* into its proper place in the ordering. */ int main(void) { int i, n; int arr[ARRAYSIZE]; /* Perform input of array of size less than or equal to ARRAYSIZE */ /* Print the array as it is for user to compare and see if it gets sorted*/ /* Now sort the array using the functions written */ sel_sort(arr, n); /* Print the array contents after the sort to see if all is well */ return 0; } int min_loc(int b[ARRAYSIZE], int k, int n) { /* Find location (index) of smallest element in b[k..n-1] */ /* Returns index of smallest element */ return pos; } void swap(int b[ARRAYSIZE], int k, int m) { /* Swap elements k and m of the integer array b */ /* Fairly simple, but watch out not to lose the value you want */ /* Must properly utilize a temp variable to hold a temp value */ int temp; temp = b[k]; b[k] = b[m]; b[m] = temp; return; } void sel_sort(int b[ARRAYSIZE], int n) { /* Sort b[0..n-1] in nondecreasing order */ int k, m; for(k=0; k < n-1; k++) /* loop through array to find small elements and swap */ /* to the proper spot in the partially sorted array */ { m = min_loc(b, k, n); /* find min value in the unsorted part */ swap(b,k,m); /* swap that min value found into the proper spot */ } return; }