插入排序

插入排序:

/// 2. 插入排序
+ (NSArray *)insertionComparable:(NSArray *)array {
    NSMutableArray *arrayM = [NSMutableArray array];
    for (NSNumber *num in array) {
        [arrayM addObject:num];
    }
    NSInteger N = arrayM.count;
    // 将array按升序排列
    for (NSInteger i = 1; i0 && arrayM[j] < arrayM[j-1]; j--) {
            [arrayM exchangeObjectAtIndex:j withObjectAtIndex:j-1];
        }
    }
    NSArray *comparableArray = arrayM.copy;
    return comparableArray;
}

你可能感兴趣的:(插入排序)