Skip to content

Instantly share code, notes, and snippets.

@marmeladze
Created July 17, 2020 11:47
Show Gist options
  • Select an option

  • Save marmeladze/905e5a3738f91fecbcebee2c898f7550 to your computer and use it in GitHub Desktop.

Select an option

Save marmeladze/905e5a3738f91fecbcebee2c898f7550 to your computer and use it in GitHub Desktop.

Complete below class

class GraphStructure:
  def __init__(self, *args):
    self.args = args

  def add_node(self, node):
    pass

  def connect(self, node1, node2):
    pass

  def show(self):
    for connection in connections:
        print(connection)

1 2 3 4 5 6

#usage

graph = Graphstructure()

graph.add_node(Node_1)
graph.add_node(Node_2)
graph.add_node(Node_3)
graph.add_node(Node_4)
graph.add_node(Node_5)
graph.add_node(Node_6)


g.connect(Node_1, Node_4)
g.connect(Node_4, Node_2)
g.connect(Node_4, Node_3)
g.connect(Node_4, Node_5)
g.connect(Node_5, Node_6)


graph.show() => 
   ...
   connections: "Node_1 -- Node_4"
   connections: "Node_4 -- Node_2"
   connections: "Node_4 -- Node_3"
   connections: "Node_4 -- Node_5"
   connections: "Node_5 -- Node_6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment