2019.4.16
private class preorderIerator implements Iterator<T>{
private ArrayList<T> list = new ArrayList<>();
private int current = 0;
public preorderIerator(){
preorder();
}
private void preorder(){
preorder(root);
}
private void preorder(TreeNode<T> root){
if(root == null)
return;
list.add(root.element);
preorder(root.left);
preorder(root.right);
}
@Override
public boolean hasNext() {
return current < list.size();
}
@Override
public T next() {
return list.get(current++);
}
}