Skip to content

Instantly share code, notes, and snippets.

@thomasbrus
Last active December 11, 2015 09:38
Show Gist options
  • Save thomasbrus/4581100 to your computer and use it in GitHub Desktop.
Save thomasbrus/4581100 to your computer and use it in GitHub Desktop.
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