Skip to content

Instantly share code, notes, and snippets.

@raymondchua
Created December 2, 2013 00:03
Show Gist options
  • Save raymondchua/7742605 to your computer and use it in GitHub Desktop.
Save raymondchua/7742605 to your computer and use it in GitHub Desktop.
define a function to construct a graph
from node import Node
def constructGraph(vertex, edges):
vertices = dict([(vertex[i],Node(vertex[i])) for i in range(len(vertex))])
for i in vertices:
vertices[i].value = i
for (u,v) in edges:
vertices[u].adjacentNodes.append(vertices[v])
#return the root node
return vertices[vertex[0]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment