Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grafos = {'ab': 6,'ac': 1, 'ad' : 7,'bc':5,'bd': 2,'cd': 4}
- floresta = []
- print(grafos)
- def ciclo(ponto,floresta):
- if len(floresta) == 0:
- floresta.append(ponto)
- print ("ok")
- else:
- for letra in ponto:
- for arvore in floresta:
- if letra == arvore[0] or letra == arvore[1]:
- floresta.append(ponto)
- print("Ponto {} adicionado".format(ponto))
- print(floresta)
- return floresta
- else:
- print("Ponto {} nao adicionado".format(ponto))
- return floresta
- def kruskar(grafos):
- grafos_ord = sorted(grafos, key = grafos.get)
- print(grafos_ord)
- kruskal = []
- for ponto in grafos_ord:
- ciclo(ponto,floresta)
- print(floresta)
- print(kruskal)
Add Comment
Please, Sign In to add comment