Guest User

Untitled

a guest
Aug 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. How to code Bubble sorting For an Array of Objects in Objective C lang.?
  2. +(void) SortAndPrintBubble:(NSMutableArray *) tosort{
  3.  
  4. Student * tmp = [Student new];
  5. for (int i = [tosort count] - 1; i >=0; i--) {
  6.  
  7. for (int j =1; j<=i; j++) {
  8. if ([[tosort objectAtIndex:(j-1)] GetGPA] > [[tosort objectAtIndex:j] GetGPA]) {
  9. tmp = [tosort objectAtIndex:(j-1)];
  10. [tosort insertObject:(id)[tosort objectAtIndex:(j-1)] atIndex:(NSUInteger)j];
  11. [tosort replaceObjectAtIndex:j withObject:(id)tmp];
  12. }
  13. }
  14.  
  15. -(NSComparisonResult) compareGPA:(Student*)otherStudent;
  16.  
  17. [tosort sortUsingSelector:@selector(compareGPA:)];
  18.  
  19. - (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context
Add Comment
Please, Sign In to add comment