冒泡选择排序

Posted guligei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了冒泡选择排序相关的知识,希望对你有一定的参考价值。

 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);
    }];

以上是关于冒泡选择排序的主要内容,如果未能解决你的问题,请参考以下文章

冒泡排序以及选择排序代码实现

三大基础排序算法(冒泡排序,选择排序,插入排序)

冒泡排序与选择排序(代码)

四种排序算法实现

[leetcode]排序算法(冒泡排序,选择排序,插入排序,快速排序,计数排序)

数组冒泡排序选择排序二分查找法