首页 > 其他 > 详细

Counting-Sort

时间:2015-12-03 08:26:24      阅读:271      评论:0      收藏:0      [点我收藏+]

 

Counting-Sort(A,B,k)

    let C[0..k] be a new array

    for i = 0 to k

           C[i] = 0

    for j = 1 to A.length

           C[A[j]] = C[A[j]] + 1

    //C[i] now contains the number of elements equal to i

    for i = 1 to k

           C[i] = C[i] + C[i-1]

     //C[i] now contains the number of elements less than or equal to i

     for j = A.length downto 1

           B[C[A[j]]] = A[j]

           C[A[j]] = C[A[j]] - 1

                                          ------<Introduction To Algorithm>

Counting-Sort

原文:http://www.cnblogs.com/rixiang/p/5014975.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!