Example #1
0
    def testBubbleDown(self):
        u"""测试堆的向下冒泡调整操作"""

        heap = Heap()
        heap._heap = [3, 2, 4, 5, 1]

        # 调整第2个元素
        heap._bubbleDown(1)
        self.assertEqual([3, 1, 4, 5, 2], heap._heap)
        # 调整根元素
        heap._bubbleDown(0)
        self.assertEqual([1, 2, 4, 5, 3], heap._heap)
Example #2
0
    def testBubbleDown(self):
        u"""测试堆的向下冒泡调整操作"""

        heap = Heap()
        heap._heap = [3, 2, 4, 5, 1]

        # 调整第2个元素
        heap._bubbleDown(1)
        self.assertEqual([3, 1, 4, 5, 2], heap._heap)
        # 调整根元素
        heap._bubbleDown(0)
        self.assertEqual([1, 2, 4, 5, 3], heap._heap)