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

桶排序-Swift

Publish:

import Foundation
 
 
let b:Array = [5,2,3,1,8]
var a:NSMutableArray = []
 
for var i in 0 ..< 11 {
    a[i] = 0
}
 
for var num in b {
    var index = NSInteger(num)
    if(a[index] as! NSInteger >= 0){
        a[index] = a[index] as! (NSInteger) + 1;
    } else {
        a[index] = 0
    }
}
 
for var i in 0 ..< a.count {
    if(a[i] as! NSInteger > 0){
        print(i)
    }
}

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