File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change 11"""
22radix sort
3- complexity: O(nk) . n is the size of input list and k is the digit length of the number
3+ complexity: O(nk + n ) . n is the size of input list and k is the digit length of the number
44"""
55def radix_sort (arr , simulation = False ):
6- is_done = False
76 position = 1
7+ max_number = max (arr )
88
99 iteration = 0
1010 if simulation :
11- print ("iteration" ,iteration ,":" ,* arr )
11+ print ("iteration" , iteration , ":" , * arr )
1212
13- while not is_done :
13+ while position < max_number :
1414 queue_list = [list () for _ in range (10 )]
15- is_done = True
1615
1716 for num in arr :
1817 digit_number = num // position % 10
1918 queue_list [digit_number ].append (num )
20- if is_done and digit_number > 0 :
21- is_done = False
2219
2320 index = 0
2421 for numbers in queue_list :
@@ -28,7 +25,8 @@ def radix_sort(arr, simulation=False):
2825
2926 if simulation :
3027 iteration = iteration + 1
31- print ("iteration" ,iteration ,":" ,* arr )
28+ print ("iteration" , iteration , ":" , * arr )
3229
3330 position *= 10
3431 return arr
32+
You can’t perform that action at this time.
0 commit comments