Tested DFS direction assisted search.

This commit is contained in:
2020-04-22 19:41:25 -05:00
parent ed48e164b6
commit 4ed9d4d272
2 changed files with 27 additions and 9 deletions

View File

@@ -14,6 +14,8 @@ public class DepthFirstSearch {
private Node endNode;
private HashSet<Node> checkedNodes;
private int maxNodesSearched = -1;
private int foundX;
private int foundY;
public DepthFirstSearch() {
checkedNodes = new HashSet<>();
@@ -43,16 +45,16 @@ public class DepthFirstSearch {
startNode = new Node(null, x, y);
}
public void setEndPosition(int x, int y) {
public void setDirectionPosition(int x, int y) {
endNode = new Node(null, x, y);
}
public int getEndX() {
return endNode.x;
return foundX;
}
public int getEndY() {
return endNode.y;
return foundY;
}
public void deleteTree() {
@@ -118,7 +120,8 @@ public class DepthFirstSearch {
n.child[2] = new Node(n, n.x, n.y + 1);
n.child[3] = new Node(n, n.x, n.y - 1);
} else {
endNode = n;
foundX = n.x;
foundY = n.y;
return true;
}
if (checkedNodes.add(n)) {
@@ -133,6 +136,9 @@ public class DepthFirstSearch {
return false;
}
public int getSearchedCount() {
return checkedNodes.size();
}
private class Node implements Comparable<Node> {
public Node[] child;
public Node parent;