Ejemplo n.º 1
0
def huffman(C):
    n = len(C)
    Q = _build_min_priority_queue(C)
    for i in between(1, n - 1):
        z = Node(None)
        z.left = x = _heap_extract_min(Q)
        z.right = y = _heap_extract_min(Q)
        z.f = x.f + y.f
        _min_heap_insert(Q, z)
    return _heap_extract_min(Q)
Ejemplo n.º 2
0
def _build_min_priority_queue(C):
    nodes = []
    for c in C:
        node = Node(None)
        node.data = c[0]
        node.f = c[1]
        nodes.append(node)
    A = Array(nodes)
    _build_min_heap(A)
    return A