首页 > 其他 > 详细

CLRS:sorting in linear time O(n)

时间:2016-05-07 22:03:17      阅读:230      评论:0      收藏:0      [点我收藏+]

//intput array A,output array result.   count array count .

//all the elements is in te range of 0~k.

//if k=O(n),the complexity is Θ(n)

//counting sort is stable 

for(i=0;i<n;i++)result[i]=0;

for(i=1;i<=n;i++)count[a[i]]++;

for(i=1;i<=n;i++)count[i]+=count[i-1];

for(j=n;j>1;j--)

{

result[count[A[j]]]=A[j];

count[A[j]]--;

}

/radix sort

//对每一位数字进行排序,收集后,递归进行,直到全部排序完成

 

 

 

//bucket sort

//按区间分布bucket,bucket内部使用insert sort.

CLRS:sorting in linear time O(n)

原文:http://www.cnblogs.com/zeroArn/p/5469254.html

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