@Override
    public Node<TypeOfState, TypeOfValue> next() {
        if (!this.hasNext())
            throw new NoSuchElementException("No more nodes to iterate.");
        Node<TypeOfState, TypeOfValue> node;
        boolean keepGoing = true;
        while (keepGoing)
        {
            node = this._stack.peekLast(); // Get current suggestion for next node.
            keepGoing = false; // Assume that node is next in the iteration.
            if (0 < node.getChildren()) { // If the node has any children:
                for (Node<TypeOfState, TypeOfValue> child : node) { // Iterate through the children:
                    if (!this._stack.contains(child) && // For any child not stacked and not done:
                            !this._done.contains(child)) {
                        this._stack.addLast(child); // Add child to stack.
                        keepGoing = true; // Because a child was added, another node is the next in the iteration.
                    }
                }
            }
        }
        node = this._stack.pollLast(); // Get next node.
        this._done.add(node); // Add return value to done nodes.
        return node;
    }