struct recordType { string stuID; // Unique student identifier int height; // Height in inches int weight; // Weight in pounds }; struct listType { recordType stuRecord[MAXSIZE]; // Array of student records int n; // Number of records in the array }; //--------------------------------------------------------- // sortById // // Purpose: sort the data in the list in ascending order by // student id. // // The selection sort algorithm is used. // // In/Out Parameter: list //--------------------------------------------------------- void sortById(listType& list) { recordType temp; // Temporary storage for a record int pass; // Counts passes through the list int pos; // Position in unsorted sublist int minPos; // Position of minimum value for(pass = 0; pass < list.n - 1; pass++) { minPos = pass; // Find the position of the minimum value for (pos = pass + 1; pos < list.n; pos++) { if (list.stuRecord[pos].stuID < list.stuRecord[minPos].stuID) { minPos = pos; } } // Swap the minimum value with the first value // in the unsorted portion of the list temp = list.stuRecord[pass]; list.stuRecord[pass] = list.stuRecord[minPos]; list.stuRecord[minPos] = temp; } } //--------------------------------------------------------- // sortByHeight // // Purpose: sort the data in the list in ascending order by // height. // // The insertion sort algorithm is used. // // In/Out Parameter: list //--------------------------------------------------------- void sortByHeight(listType& list) { recordType temp; // Temporary storage for a record int pos; // Position in sorted sublist. for(int i = 1; i < list.n; i++) { if (list.stuRecord[i].height < list.stuRecord[i-1].height) { temp = list.stuRecord[i]; pos = i; do { list.stuRecord[pos] = list.stuRecord[pos - 1]; pos--; } while (pos > 0 && temp.height < list.stuRecord[pos - 1].height); list.stuRecord[pos] = temp; } } }