Created
December 16, 2014 20:07
-
-
Save ajrouvoet/e46d14ee4d6cbf61019c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class Node { | |
val connections: ListBuffer[Connection] = new ListBuffer[Connection] | |
} | |
case class Connection( | |
from: Node, | |
val to: Node, | |
val cost: Int, | |
private val directed: Boolean = true | |
) { | |
from.connections += this | |
if(!directed) to.connections += new Connection(to, from, cost, true) | |
} | |
class Graph { | |
val nodes: ListBuffer[Node] = new ListBuffer[Node] | |
def getConnections(node: Node): Option[List[Connection]] = { | |
nodes.find(n => n == node) match { | |
case Some(node) => | |
Some(node.connections.toList) | |
case None => | |
None | |
} | |
} | |
} | |
object GraphTest1 extends App { | |
val nodeA = new Node() | |
val nodeB = new Node() | |
val con: Connection = new Connection(nodeA, nodeB, 5) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment