Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to code Bubble sorting For an Array of Objects in Objective C lang.?
- +(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];
- }
- }
- -(NSComparisonResult) compareGPA:(Student*)otherStudent;
- [tosort sortUsingSelector:@selector(compareGPA:)];
- - (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context
Add Comment
Please, Sign In to add comment