I am trying to make a node class that I will eventually be able to use for a minimax search, however I am having trouble iterating over all of the nodes in my tree (in this case for a simple to string function).

Here is the definition of the recursive to string method.

```
    public String toString(){
        if(!this.isLeaf()){
            String text = "";
            Iterator<Node<T>> iter = children.iterator();
            while(iter.hasNext()){
                    Node child = iter.next();
                    text = "/" + child.toString();
            }
            return text;
        }else{

            return cargo.toString() ;
        }
    }

```

After reading other answers I tried using the Iterator interface as seen in the code above but it still didn't work. (I'm also open to non-recursive methods of doing this)