Guest User

Untitled

a guest
Mar 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. @Override
  2. public Iterator<E> iterator() {
  3. int expectedModCount = modCount;
  4. return new Iterator<E>() {
  5. BinNode<E> curr = root;
  6. @Override
  7. public boolean hasNext() {
  8. return curr != null;
  9. }
  10.  
  11. @Override
  12. public E next() {
  13. checkModCount();
  14. //todo
  15. return ;
  16. }
  17.  
  18.  
  19. private void checkModCount() {
  20. if (expectedModCount != modCount) {
  21. throw new ConcurrentModificationException();
  22. }
  23. }
  24. };
  25. }
  26.  
  27. class Node {
  28. Object value;
  29. Node left, right;
  30. }
  31.  
  32. void go(Node root) {
  33. go(root.left);
  34. go(root.right);
  35. }
  36.  
  37. class NodeIterator implements Iterator {
  38. Stack<Node> nodes;
  39.  
  40. public NodeIterator(Node root) {
  41. nodes.push(root);
  42. }
  43. boolean hasNext() {
  44. return nodes.size > 0;
  45. }
  46. Object next() {
  47. Node current = nodes.peek();
  48. if (current.left != null)
  49. nodes.push(current.left);
  50. else if (current.right)
  51. nodes.push(current.right);
  52. else
  53. nodes.pop();
  54. return current.value;
  55. }
  56. }
Add Comment
Please, Sign In to add comment