首页 > 随笔档案 > 桶排序-OC

桶排序-OC

Publish:

 NSArray * b = @[@5,@2,@3,@1,@8];
    NSMutableArray *a = @[].mutableCopy;
    for (int i=0; i<11; i++) {
        a[i] = @0;
    }
    for (NSNumber *num in b) {
        int index = [num intValue];
        if(a[index]){
            a[index] = @([a[index] intValue] + 1);
        } else {
            a[index] = @0;
        }
    }
    for (int i = 0; i<a.count; i++) {
        if([a[i] intValue]>0){
            NSLog(@"%d",i);
        }
    }

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: levy