Created
October 18, 2014 23:37
-
-
Save ryanseys/31f0302c63eeb8e476af to your computer and use it in GitHub Desktop.
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
function Graph() { | |
this.nodes = []; | |
this.edges = []; | |
}; | |
Graph.prototype.addNode = function(node) { | |
if(node) { | |
this.nodes.push(node); | |
} | |
}; | |
Graph.prototype.addEdge = function(edge) { | |
if(edge && edge.start && edge.end) { | |
this.edges.push(edge); | |
} | |
} | |
function Node(value) { | |
this.value = value; | |
}; | |
Node.prototype.setValue = function(value) { | |
this.value = value; | |
}; | |
Node.prototype.getValue = function() { | |
return value; | |
}; | |
function Edge(start, end) { | |
this.start = start; | |
this.end = end; | |
}; | |
Edge.prototype.getStart = function() { | |
return this.start; | |
}; | |
Edge.prototype.getEnd = function() { | |
return this.end; | |
}; | |
Edge.prototype.setStart = function(start) { | |
this.start = start; | |
}; | |
Edge.prototype.setEnd = function(end) { | |
this.end = end; | |
}; | |
var g = new Graph(); | |
var n1 = new Node("world"); | |
var n2 = new Node("hello"); | |
var e1 = new Edge(n1, n2); | |
g.addNode(n1); | |
g.addNode(n2); | |
g.addEdge(e1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment