桶排序-Swift

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

 

posted @ 2016-09-22 15:24  levyleo  阅读(159)  评论(0编辑  收藏  举报