算法
流程图
流程图
计数排序
a = {
'0':0,
'1':2,
'2':1,
'3':6,
'4':4,
'5':9,
'6':3,
'length':7
}
hash = [];
index = 0;
maxIndex = 0;
while index < a['length']
number = a[index]
if hash[number] == undefined // hash[number] 不存在
hash[number] = 1
else
hash[number] = hash[number] ++
while a[maxIndex] < a[index]
maxIndex = index
index = index ++
end
index2 = 0
max = a[maxIndex] // 最大值9
newArr = []
while index2 <= max
count =0
if count < has[index2]
newArr.push(index2)
count = count ++
end
index2 = index2 ++
end
print newArr
end
image.png
网友评论