Пример #1
0
 /** @return dfs wenn gefunden, ansonsten NULL */
 @Override
 public Graph<Integer> dfs(Node<Integer> start, Node<Integer> goal) {
   this.unvisitAllNodes();
   Graph<Integer> dfs = new ImplGraph();
   dfs.setNode(start.value());
   boolean found = this.dfs(start, goal, dfs);
   return found ? dfs : null;
 }
Пример #2
0
 private boolean dfs(
     final Node<Integer> node, final Node<Integer> goal, Graph<Integer> accumulator) {
   try {
     this.visitNode(node);
     if (node.value() == goal.value()) {
       return true;
     }
     ArrayList<Node<Integer>> stack = this.adjacencyList.get(node);
     for (Node<Integer> next : stack) {
       if (!this.isVisited(next) && next.value() != node.value()) {
         accumulator.setNode(next.value());
         accumulator.setEdge(next, node);
         if (dfs(next, goal, accumulator)) {
           return true;
         }
       }
     }
     return false;
   } catch (NodeNotFoundException e) {
     System.out.println("darf net passiern damn!");
     return false;
   }
 }