码迷,mamicode.com
首页 > 其他好文 > 详细

Counting-Sort

时间:2015-12-03 08:27:41      阅读:156      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!