Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Iterator<E> iterator() {
- int expectedModCount = modCount;
- return new Iterator<E>() {
- BinNode<E> curr = root;
- @Override
- public boolean hasNext() {
- return curr != null;
- }
- @Override
- public E next() {
- checkModCount();
- //todo
- return ;
- }
- private void checkModCount() {
- if (expectedModCount != modCount) {
- throw new ConcurrentModificationException();
- }
- }
- };
- }
- class Node {
- Object value;
- Node left, right;
- }
- void go(Node root) {
- go(root.left);
- go(root.right);
- }
- class NodeIterator implements Iterator {
- Stack<Node> nodes;
- public NodeIterator(Node root) {
- nodes.push(root);
- }
- boolean hasNext() {
- return nodes.size > 0;
- }
- Object next() {
- Node current = nodes.peek();
- if (current.left != null)
- nodes.push(current.left);
- else if (current.right)
- nodes.push(current.right);
- else
- nodes.pop();
- return current.value;
- }
- }
Add Comment
Please, Sign In to add comment