SHARE
TWEET

Untitled

a guest Jan 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. g = { "a" : {"d":2},
  2.       "b" : {"c":2},
  3.       "c" : {"b":5,  "d":3, "e":5}
  4.     }
  5. graph = Graph(g)
  6. print("Vertices of graph:")
  7. print(graph.vertices())
  8. print("Edges of graph:")
  9. print(graph.edges())
  10. print("Add vertex:")
  11. graph.add_vertex("z")
  12. print("Vertices of graph:")
  13. print(graph.vertices())
  14. print("Add an edge:")
  15. graph.add_edge({"a","z"})    
  16. print("Vertices of graph:")
  17. print(graph.vertices())
  18. print("Edges of graph:")
  19. print(graph.edges())
  20. print('Adding an edge {"x","y"} with new vertices:')
  21. graph.add_edge({"x","y"})
  22. print("Vertices of graph:")
  23. print(graph.vertices())
  24. print("Edges of graph:")
  25. print(graph.edges())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top