计数排序伪代码及流程图

a <- {

    '0':0,

    '1':2,

    '2':1,

    '3':56,

    '4':4,

    '5':67,

    '6':3,

    'length:7'

}

hash <- {}

index <- 0

while index < a['length']

    number <- a[index]

    if hash[number] == undefined // hash[number] 不存在

        hash[number] = 1

    else

        hash[number] <- hash[number] + 1

    end

    index <- index + 1

end

index2 <- 0

max <- findMax(a) // 最大值67

newArr <- {}

while index2 < max + 1

    count <- hash[index2]

    if count != undefined // count 存在

        countIndex <- 0

        while countIndex < count

            newArr.push(index2)

            countIndex <- countIndex + 1

        end

    end

    index2 <- index2 + 1

end

print newArr


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Lua 5.1 参考手册 by Roberto Ierusalimschy, Luiz Henrique de F...
    苏黎九歌阅读 14,735评论 0 38
  • 事情发生在当我读到《撒哈拉的故事》一百五十七页的时候。 文章的原句是" ……除了在风沙...
    韦嵩阅读 3,311评论 0 3
  • 于2013年毕业,现今已有3年多的时间,朋友同学们个个都风生水起,混得不错,再看看自己,还在原地打转,太失败了。这...
    乐视薯片阅读 968评论 1 2
  • 7 把樽刻苦泪 饮杯铭心恨 你构你的愿景 我思我的梦境 一样的心 一样的情 当晚霞染红了天空的时候,你起身,好像随...
    逐日钩沉阅读 2,920评论 0 2