首页 > 编程语言 > 详细

冒泡选择排序

时间:2018-08-14 13:51:44      阅读:272      评论:0      收藏:0      [点我收藏+]
 NSMutableArray *mArray = [NSMutableArray arrayWithObjects:@4,@5,@9,@2,@3,@3,@2,@7, nil];
   
    for (int i = 0; i<mArray.count-1; i++) {
        for (int j = 0; j<mArray.count - i-1; j++) {
            if (mArray[i] < mArray[i+1]) {
                NSInteger temp = [mArray[i+1]integerValue];
                mArray[i+1] = mArray[i];
                mArray[i] = [NSNumber numberWithInteger:temp];
            }
        }
    }
    
    
    for (int i = 0; i<mArray.count-1; i++) {
        for (int j = 0; j<mArray.count - i-1; j++) {
            if (mArray[j] < mArray[j+1]) {
                NSInteger temp = [mArray[j+1]integerValue];
                mArray[j+1] = mArray[j];
                mArray[j] = [NSNumber numberWithInteger:temp];
            }
        }
    }
    
    
    for (int i = 0; i<mArray.count-1; i++) {
        for (int j = i; j<mArray.count-1; j++) {
            if (mArray[j]<mArray[j+1]) {
                NSInteger temp = [mArray[j+1]integerValue];
                mArray[j+1] = mArray[j];
                mArray[j] = [NSNumber numberWithInteger:temp];
            }
        }
    }
    
    
    for (int i = 0; i<mArray.count-1; i++) {
        for (int j = i; j<mArray.count-1; j++) {
            if (mArray[i]<mArray[j+1]) {
                NSInteger temp = [mArray[j+1]integerValue];
                mArray[j+1] = mArray[i];
                mArray[i] = [NSNumber numberWithInteger:temp];
            }
        }
    }
    
    
   
    
    [mArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"value %@",obj);
    }];

冒泡选择排序

原文:https://www.cnblogs.com/guligei/p/9473511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!