I am trying to sort a list of students by their ID numbers in ascending order. Along with their IDs are program and test averages. I have used a struct to hold all three of these items for each student. My program compiles, but it does not do the sorting. Does any one know what I'm missing?
void sortAr(persons[], int count)
{
int min,
i;
for (int i= 0; i < count; i++) //this loops checks for the smallest id value
{
int min = i;
for (int temp = i + 1; temp < count; temp++)
if (student[temp].studentID < student[min].studentID)
min = temp;
swap(student[i].studentID, student[min].studentID); //if a student ID is smaller than the past, the swap will
swap (student[i].programAvg, student[min].programAvg); //put them in ascending order
swap (student[i].testAvg, student[min].testAvg);
bool student_id_asc(const persons& a, const persons& b) // comparison function
{
return a.studentID < b.studentID;
}
1 2
std::sort(student.begin(), student.end(), student_id_asc);
std::sort(student, student + size_of_array, student_id_asc); // if you are not using an stl container