import gen_num num_lst = gen_num.gen_num2(20) print(num_lst) print(sorted(num_lst)) min_num = min(num_lst) max_num = max(num_lst) count = [0 for _ in range(max_num - min_num + 1)] #[0,max-min] # print(count) for i in num_lst: count[i - min_num] = count[i - min_num] + 1 print(count) result = [] for j in range(len(count)): while count[j] > 0: result.append(j + min_num) count[j] = count[j] - 1 print(result)
import gen_num num_lst = gen_num.gen_num2(30) print(num_lst) def count_sort(A): min_num = min(A) max_num = max(A) delta = max_num-min_num count = [0 for i in range(min_num,max_num+1)] for item in A: count[item-min_num] +=1 print(count) result = [] for i in range(len(count)): while count[i]>0: result.append(i+min_num) count[i] -=1 return result print(count_sort(num_lst))
import gen_num num_lst = gen_num.gen_num2(15) print(num_lst) def count_sort(A): ''' Args: A:num_lst ''' max_value = max(A) min_value = min(A) count_list = [0 for i in range(min_value, max_value + 1)] for num in A: count_list[num - min_value] += 1 result = [] for i in range(len(count_list)): #[0,n-1] if count_list[i] > 0: result.append(i + min_value) return result print(count_sort(num_lst))
import gen_num lst = gen_num.gen_num1(100) print('lst:', lst) lst2 = gen_num.gen_num2(100) print('lst2:', lst2)