I am guessing that you have to write your own sort function (like a bubble sort).
If that's the case, then you should already know the algorithm. Bubble sort
compares two elements. In your case, they are studentGrade structs. You
should compare only the "grade" member of the two structs. This will have
the effect of sorting by grade. ie, if( student[idx].grade < student[idx+1].grade )
If you are allowed to use std::sort(), then the problem is much easier, in
which case you can do as kempofighter suggested (write operator< for
studentGrade).
NB: you can still write operator< for studentGrade if you have to write
your own sort routine. In which case your if() would be
if( student[idx] < student[idx+1] ), which will call operator< on
studentGrade.
And there are still other, even shorter ways to do it, but they require
boost::lambda or boost::multi_index_container.
EDIT: Ok, so I can't resist.
1 2 3
|
std::sort( student, student + count,
&boost::lambda::_1->*&studentGrade::grade <
&boost::lambda::_2->*&studentGrade::grade );
|
And the whole thing is sorted by grade.