美文网首页
计数排序伪代码及流程图

计数排序伪代码及流程图

作者: elsa919 | 来源:发表于2018-11-26 16:31 被阅读45次

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

相关文章

网友评论

      本文标题:计数排序伪代码及流程图

      本文链接:https://www.haomeiwen.com/subject/riibqqtx.html