def test_delete_min(self):
        heap = self.build_basic_heap()

        self.assertEqual(2, heap.delete_min())

        self.assertEqual([0, 5, 7, 12, 23, 34, 88], heap.heap_list)

        heap = Heap()

        self.assertEqual(None, heap.delete_min())

        heap.insert(4)

        self.assertEqual(4, heap.delete_min())
示例#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