def test_build(self):

        built = Heap()

        built.build([23, 12, 7, 5, 34, 88, 2])

        self.assertEqual([0, 2, 5, 7, 12, 34, 88, 23], built.heap_list)
Beispiel #2
0
def custom_heap_sort(lst: list, sort='min'):
    copy_list = deepcopy(lst)
    if sort == 'max':
        copy_list = list(map(lambda x: x * -1, copy_list))
    heap = Heap()
    heap.build(copy_list)
    sorted_list = [heap.delete_min() for i in range(heap.size())]
    if sort == 'max':
        sorted_list = list(map(lambda x: x * -1, sorted_list))
    return sorted_list