I've written the function below to Sort(Bubble) an Array of objects according to the Max GPA.
Please note that tmp is an object of class Student which includes ( Name , age , GPA ),there's another loop to print the result.
But , it's not Sorting ( Not Functional),No erros , just not working, please Assist.... i.e : output : Result not sorted
+(void) SortAndPrintBubble:(NSMutableArray *) tosort{
Student * tmp = [Student new];
for (int i = [tosort count] - 1; i >=0; i--) {
for (int j =1; j<=i; j++) {
if ([[tosort objectAtIndex:(j-1)] GetGPA] > [[tosort objectAtIndex:j] GetGPA]) {
tmp = [tosort objectAtIndex:(j-1)];
[tosort insertObject:(id)[tosort objectAtIndex:(j-1)] atIndex:(NSUInteger)j];
[tosort replaceObjectAtIndex:j withObject:(id)tmp];
}
}