我创建得stu1 stu2 stu3 stu4 stu5  里都有学生姓名    性别  数学成绩 然后把他们都放到数组里
NSArray *array = [[NSArray alloc] initWithObjects:stu1,stu2,stu3,stu4,stu5,nil];
我想按照数学成绩排序 
应该怎么运用下面得方法啊  怎么修改啊
NSArray * sortArray =[array sortedArrayUsingSelector:@selector(compare:)];

解决方案 »

  1.   


    -(NSComparisonResult) compare:(stu*) other {
        if (⋯⋯) {
            return NSOrderedDescending;
        }else if (⋯⋯) {
            return NSOrderedAscending;
        }
    ⋯⋯
      

  2.   

    其实和冒泡排序差不多嘛,你比较一下stu.math,然后冒泡,就可以搞定了
      

  3.   

    iphone技术交流群,4633616,欢迎加入探讨。