def test__heap_sort(self): for items, ans in self.user_cases: sorts.heap_sort(items) self.assertEqual(items, ans) for items in self.generate_cases(self.n_cases): ans = sorted(items) t1 = time.time_ns() sorts.heap_sort(items) self.ts.append(time.time_ns() - t1) self.assertEqual(items, ans)
def test_heap_sort(self): a = [5, 8, 1, 9, 6, 3, 10, 7, 2, 4] b = a.copy() b.sort() heap_sort(a) self.assertEqual(a, b) c = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] d = c.copy() d.sort() heap_sort(c) self.assertEqual(c, d)
def main(argv): n, A = files.read_lines_of_ints(argv[0]) print ' '.join(str(a) for a in sorts.heap_sort(A))
#!/usr/bin/env python from sorts import insertion_sort, merge_sort, heap_sort, build_heap arr = ['a', 'c', 'b', 'f', 'd', 'aa', 'zzzzzz'] print arr merge_sort(arr) print arr arr = ['a', 'c', 'b', 'f', 'd', 'aa', 'zzzzzz'] print arr insertion_sort(arr) print arr arr = ['a', 'c', 'b', 'f', 'd', 'aa', 'zzzzzz'] print arr heap_sort(arr) print arr arr = ['a', 'c', 'b', 'f', 'd', 'aa', 'zzzzzz'] print arr build_heap(arr) print arr
from random import randint import logging from copy import copy import sorts if __name__ == '__main__': N_list = [50000] ROUND = 1 logging.basicConfig(level=logging.INFO) for N in N_list: randint_list = [[randint(0, 2 ** 31 - 1) for _ in range(N)] for _ in range(ROUND)] for i in range(ROUND): bubble_list = copy(randint_list[i]) insertion_list = copy(randint_list[i]) selection_list = copy(randint_list[i]) quick_list = copy(randint_list[i]) heap_list = copy(randint_list[i]) sorts.bubble_sort(bubble_list) sorts.insertion_sort(insertion_list) sorts.selection_sort(selection_list) sorts.quick_sort(quick_list) sorts.heap_sort(heap_list)