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

Radix Sort

时间:2020-05-01 00:45:46      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:element   val   list   creat   seq   The   dig   nts   sub   

To illustrate the radix sort algorithm we will sort the sequence S0 = {32, 100, 11, 554, 626, 122, 87, 963, 265, 108, 9}. We start by distributing elements of S0 by the value of 0-place digit (the one‘s place):

bucket 0:  100
bucket 1:  11
bucket 2:  32, 122
bucket 3:  963
bucket 4:  554
bucket 5:  265
bucket 6:  626
bucket 7:  87
bucket 8:  108
bucket 9:  9


Stitch the bucket lists to create S1 = {100, 11, 32, 122, 963, 554, 265, 626, 87, 108, 9}. Distribute elements of S1 by the value of 1-place digit (the ten‘s place):

bucket 0: 100, 108, 9
bucket 1: 11
bucket 2: 122, 626
bucket 3: 32
bucket 4:
bucket 5: 554
bucket 6: 963, 265
bucket 7:
bucket 8: 87
bucket 9:


Stitch the bucket lists to create S2 = {100, 108, 9, 11, 122, 626, 32, 554, 963, 265, 87}. Distribute elements of S2 by the value of 2-place digit (the hundred‘s place):

bucket 0: 9, 11, 32, 87
bucket 1: 100, 108, 122
bucket 2: 265
bucket 3:
bucket 4:
bucket 5: 554
bucket 6: 626
bucket 7:
bucket 8:
bucket 9: 963


Stitch the bucket lists to create S3 = {9, 11, 32, 87, 100, 108, 122, 265, 554, 626, 963}. The list is sorted.

Radix Sort

标签:element   val   list   creat   seq   The   dig   nts   sub   

原文地址:https://www.cnblogs.com/JasperZhao/p/12812204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!