Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. grafos = {'ab': 6,'ac': 1, 'ad' : 7,'bc':5,'bd': 2,'cd': 4}
  2. floresta = []
  3.  
  4. print(grafos)
  5.  
  6. def ciclo(ponto,floresta):
  7. if len(floresta) == 0:
  8. floresta.append(ponto)
  9. print ("ok")
  10. else:
  11. for letra in ponto:
  12. for arvore in floresta:
  13. if letra == arvore[0] or letra == arvore[1]:
  14. floresta.append(ponto)
  15. print("Ponto {} adicionado".format(ponto))
  16. print(floresta)
  17. return floresta
  18. else:
  19.  
  20. print("Ponto {} nao adicionado".format(ponto))
  21. return floresta
  22.  
  23.  
  24. def kruskar(grafos):
  25. grafos_ord = sorted(grafos, key = grafos.get)
  26. print(grafos_ord)
  27. kruskal = []
  28. for ponto in grafos_ord:
  29. ciclo(ponto,floresta)
  30. print(floresta)
  31. print(kruskal)
Add Comment
Please, Sign In to add comment