Last active
December 11, 2015 09:38
-
-
Save thomasbrus/4581100 to your computer and use it in GitHub Desktop.
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
boolean isPartOfCycle(int[][] matrix, Edge e) { | |
// Verwijder edge vw | |
matrix[v][w] = matrix[w][v] = 0; | |
Node v = e.node1; | |
Node w = e.node2; | |
// Bepaal of er een pad is van v naar w | |
List<Node> reachableNodes = getReachableNodes(matrix, v); | |
return reachableNodes.contains(w); | |
} | |
List<Node> getReachableNodes(int[][] matrix, Node n) { | |
List<Node> reachableNodes = new ArrayList<Node>(); | |
// Voeg alle nodes toe die deze node kan bereiken, | |
// exclusief zichzelf | |
for (int i = 0; i < matrix.length; i++) { | |
if (matrix[i][n] == 1) { | |
adjacentNode = new Node(i); | |
reachableNodes.add(adjacentNode); | |
reachableNodes.addAll(getReachableNodes(matrix, adjacentNode); | |
} | |
} | |
return reachableNodes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment