Can a BFS be implemented without a queue or stack?
<p>I was wondering how I could do this without using a queue or a hashTable but instead use a fixed array for the lookup table. This is my BFS algorithm for solving a 2x2 rubiks cube. What I want to do is store all the positions searched with its solution in a file so that if I was to give the program a scrambled cube it will search for that state of the cube and print out the solution for it. </p>

<pre><code>static private void solve(Cube c) {
    Set&lt;Cube&gt; cubesFound = new HashSet&lt;Cube&gt;();
    cubesFound.add(c);

    Stack&lt;Cube&gt; s = new Stack&lt;Cube&gt;();
    s.push(c);

    Set&lt;Stack&lt;Cube&gt;&gt; initialPaths = new HashSet&lt;Stack&lt;Cube&gt;&gt;();
    initialPaths.add(s);

    solve(initialPaths, cubesFound);
}

static private void solve(Set&lt;Stack&lt;Cube&gt;&gt; livePaths, Set&lt;Cube&gt; cubesFoundSoFar) {
    System.out.println("livePaths size:" + livePaths.size());
    int numDupes = 0;

    Set&lt;Stack&lt;Cube&gt;&gt; newLivePaths = new HashSet&lt;Stack&lt;Cube&gt;&gt;();

    for(Stack&lt;Cube&gt; currentPath : livePaths) {

        Set&lt;Cube&gt; nextStates = currentPath.peek().getNextStates();

        for (Cube next : nextStates) {
            if (currentPath.size() &gt; 1 &amp;&amp; next.isSolved()) {
                currentPath.push(next);
                System.out.println("Path length:" + currentPath.size());
                System.out.println("Path:" + currentPath);
                System.exit(0);

            } else if (!cubesFoundSoFar.contains(next)) {
                Stack&lt;Cube&gt; newCurrentPath = new Stack&lt;Cube&gt;();
                newCurrentPath.addAll(currentPath);
                newCurrentPath.push(next);
                newLivePaths.add(newCurrentPath);
                cubesFoundSoFar.add(next);
            } else {
                numDupes += 1;
            }
        }
    }

    System.out.println("Duplicates found " + numDupes + ".");
    solve(newLivePaths, cubesFoundSoFar);
}


private Cube() {
    cube = new int[][] {
        { 0, 0, 0, 0 },
        { 1, 1, 1, 1 },
        { 2, 2, 2, 2 },
        { 3, 3, 3, 3 },
        { 4, 4, 4, 4 },
        { 5, 5, 5, 5 }
    };
    cube = scanCube(cube);
    cube = print_cube(cube);
 //scanCube is just a method that takes input of the state of the cube in 2d array form
 //print_cube is a method formats the 2d array to look like a flat cube.
}

private Cube(Cube other) {
    cube = new int[other.cube.length][];
    for (int i = 0; i &lt; other.cube.length; i++) {
        cube[i] = Arrays.copyOf(other.cube[i], other.cube[i].length);
    }

}



private boolean isSolved() {
    for (int i = 0; i &lt; cube.length; i++) {
        for (int k = 1; k &lt; cube[i].length; k++) {
            if (cube[i][0] != cube[i][k]) {
                return false;
            }
        }
    }
    return true;
}

@Override
public boolean equals(Object other) {

     return other instanceof Cube &amp;&amp; Arrays.deepEquals(((Cube) other).cube, cube);
}
</code></pre>