def radix_sort(items): max_len = len(str(max(items))) def key_func(index): def _key(x): return (x/10**index) % 10 return _key for i in range(max_len): items = counting_sort(items, 10, key_func(i)) return items
quick.quick_sort(quickSequence) endTime = time.time() table_quick[size][cicle] = endTime - startTime print size print "done-quick/bubble" #counting - k=3 for cicle in range(5): for size in range(Steps): realSize = MaxSize/Steps*size if MaxSize/Steps*size > 1 else 2 sequence = getSequence(realSize) countingSequence = sequence[:] startTime = time.time() counting.counting_sort(countingSequence,0,100) endTime = time.time() table_counting_small[size][cicle] = endTime - startTime print size print "done-counting(3)" #counting - k=10 for cicle in range(5): for size in range(Steps): realSize = MaxSize/Steps*size if MaxSize/Steps*size > 1 else 2 sequence = getSequence(realSize,0,100000) countingSequence = sequence[:] startTime = time.time() counting.counting_sort(countingSequence,0,100000)
from bucket import bucket_sort from counting import counting_sort from pigeonhole import pigeonhole_sort from radix import radix_sort import time A = [] path = "/home/luca/Projects/Experiments/SpeedIndeed/input/Ages/age500000.txt" with open(path, 'r') as file: A = file.readlines() for i in range(len(A)): A[i].strip() A[i] = int(A[i]) start = time.time() A = counting_sort(A) # here call whatever algorithm you've chosen end = time.time() - start print(end) # you can uncomment this block if want to store the result in another file # with open('output.txt', 'w') as file: # for n in A: # file.write(str(n)+'\n')