Beispiel #1
0
def bfs_com_bags(g, vertice_ini):
    for vertex in g:
        vertex.dist = float('inf')
    vertice_ini.dist = 0
    d = 0
    bag_size = math.ceil(math.log2(g.qtd_vertices))
    V = Bag(bag_size)
    V.insert(vertice_ini)
    while len(V) is not 0:
        V2 = Bag(bag_size)
        processLayer(g, V, V2, d)
        V = V2
        d += 1
def intersection(B1, B2):
    """
    This function creates a bag object, then iterates through the items in both bag objects
    created by the user. It then records the count for every item in both user objects and
    compares the counts. The function casts the minimum count into the object created by
    the function.
    """
    BagIntersection = Bag()
    for item in B1.items():
        if item in B2.items():
            for count in range(min(B1.count(item), B2.count(item))):
                BagIntersection.insert(item)
    return BagIntersection
    """BagIntersection = Bag()
def union(B1, B2):
    """
    This function creates a bag object and iterates through the two bag objects that were
    created by the user. It will go through the two objects and insert the items in that
    object into the original bag object created by the function.
    """
    BagUnion = Bag()
    for item in B1.items():
        for j in range(B1.count(item)):
            BagUnion.insert(item)
        #union.append(item)
    for item2 in B2.items():
        for j2 in range(B2.count(item2)):
            BagUnion.insert(item2)
    return BagUnion