heap_sort_image.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Algorithms 作者: gonewbee 项目源码 文件源码
def draw_heap(cls, draw, a, num, i=-1, j=-1, ck=-1, cw=-1):
        for n, v in enumerate(a):
            if n > num:
                break
            # ??????????
            heap_ny = int(math.log2(n + 1))
            # ??????????
            heap_nx_a = 2**heap_ny
            # ?????????
            nx = n + 1 - heap_nx_a
            # ?????x???????
            bx = (2**(cls.heap_hn - heap_ny) - 1) * cls.heap_xs / 2
            # ?????x?????
            xs = 2**(cls.heap_hn - heap_ny) * cls.heap_xs
            # ???x??
            x = cls.heap_bx + bx + xs * nx
            # ???y??
            y = cls.heap_by + cls.heap_ys * heap_ny
            cls.heap_xy[n] = [x, y]
            # print(x, y)
            draw.text((x, y), v, (0, 0, 0))
            if n > 0:
                k = (n - 1) // 2
                kx, ky = cls.heap_xy[k]
                draw.line((x, y, kx, ky + 10), (0, 0, 0))
        if i != -1 and j != -1:
            x1, y1 = cls.heap_xy[i]
            x2, y2 = cls.heap_xy[j]
            draw.line((x1, y1 + 10, x2, y2), (255, 0, 0), width=2)
        if ck != -1 and cw != -1:
            x1, y1 = cls.heap_xy[ck]
            x2, y2 = cls.heap_xy[cw]
            draw.line((x1, y1 + 10, x2, y2), (0, 255, 255))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号