Created
December 2, 2013 00:03
-
-
Save raymondchua/7742605 to your computer and use it in GitHub Desktop.
define a function to construct a graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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