From 00ef77c6fe8b61b85108afb6945c1c99a0745977 Mon Sep 17 00:00:00 2001 From: InnoFang Date: Mon, 3 Sep 2018 08:32:02 +0800 Subject: [PATCH 1/2] fix sort/radix_sort (#395) --- algorithms/sort/radix_sort.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/algorithms/sort/radix_sort.py b/algorithms/sort/radix_sort.py index dd4113d05..8598c2f5b 100644 --- a/algorithms/sort/radix_sort.py +++ b/algorithms/sort/radix_sort.py @@ -1,24 +1,21 @@ """ radix sort -complexity: O(nk) . n is the size of input list and k is the digit length of the number +complexity: O(nk + n) . n is the size of input list and k is the digit length of the number """ def radix_sort(arr, simulation=False): - is_done = False position = 1 + max_number = max(arr) iteration = 0 if simulation: - print("iteration",iteration,":",*arr) + print("iteration", iteration, ":", *arr) - while not is_done: + while position < max_number: queue_list = [list() for _ in range(10)] - is_done = True for num in arr: digit_number = num // position % 10 queue_list[digit_number].append(num) - if is_done and digit_number > 0: - is_done = False index = 0 for numbers in queue_list: @@ -28,7 +25,7 @@ def radix_sort(arr, simulation=False): if simulation: iteration = iteration + 1 - print("iteration",iteration,":",*arr) + print("iteration", iteration, ":", *arr) position *= 10 - return arr + return arr \ No newline at end of file From 9057f8f78c09131a9eecfdf330fdf008199caaf8 Mon Sep 17 00:00:00 2001 From: InnoFang Date: Tue, 4 Sep 2018 16:33:38 +0800 Subject: [PATCH 2/2] Add a new line for radix_sort.py --- algorithms/sort/radix_sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algorithms/sort/radix_sort.py b/algorithms/sort/radix_sort.py index 8598c2f5b..89a2dbcc9 100644 --- a/algorithms/sort/radix_sort.py +++ b/algorithms/sort/radix_sort.py @@ -28,4 +28,5 @@ def radix_sort(arr, simulation=False): print("iteration", iteration, ":", *arr) position *= 10 - return arr \ No newline at end of file + return arr + \ No newline at end of file