Created
July 13, 2021 21:46
-
-
Save Jacke/c89e6de4fd14506fd3341ac3799e8457 to your computer and use it in GitHub Desktop.
Graph Abstract with Subclasses
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
class Graph { | |
class Node { | |
var connectedNodes: List[Graph#Node] = Nil | |
def connectTo(node: Graph#Node): Unit = { | |
if (!connectedNodes.exists(node.equals)) { | |
connectedNodes = node :: connectedNodes | |
} | |
} | |
} | |
var nodes: List[Node] = Nil | |
def newNode: Node = { | |
val res = new Node | |
nodes = res :: nodes | |
res | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment