def counting_sort(a, k): c = new_zero_array(k) for i in range(len(a)): c[a[i]] += 1 for i in range(1, k): c[i] += c[i - 1] b = new_array(len(a)) for i in range(len(a) - 1, -1, -1): c[a[i]] -= 1 b[c[a[i]]] = a[i] return b
def counting_sort(a, k): c = new_zero_array(k) for i in range(len(a)): c[a[i]] += 1 for i in range(1, k): c[i] += c[i-1] b = new_array(len(a)) for i in range(len(a)-1, -1, -1): c[a[i]] -= 1 b[c[a[i]]] = a[i] return b
def radix_sort(a): for p in range(w//d): c = new_zero_array(1<<d) b = new_array(len(a)) for i in range(len(a)): bits = (a[i] >> d*p)&((1<<d)-1) c[bits] += 1 for i in range(1, 1<<d): c[i] += c[i-1] for i in range(len(a)-1, -1, -1): bits = (a[i] >> d*p)&((1<<d)-1) c[bits] -=1 b[c[bits]] = a[i] a = b return b
def radix_sort(a): for p in range(w // d): c = new_zero_array(1 << d) b = new_array(len(a)) for i in range(len(a)): bits = (a[i] >> d * p) & ((1 << d) - 1) c[bits] += 1 for i in range(1, 1 << d): c[i] += c[i - 1] for i in range(len(a) - 1, -1, -1): bits = (a[i] >> d * p) & ((1 << d) - 1) c[bits] -= 1 b[c[bits]] = a[i] a = b return b