public void buildTree() { int[] arr = { 5, 2, 8, 1, 9, 6, 3, 7, 4, 10 }; foreach (int i in arr) root = insert(root, i, null); }
//Pass root of the current binary tree public InOrderIterator(Node root) { while (root.left != null) root = root.left; next = root; //While initializing the iterator, set next node to first node of inorder traversal }
public Node(int data, Node left, Node right, Node parent) { this.data = data; this.left = left; this.right = right; this.parent = parent; }
private Node MinNode(Node node) { if (node == null) return node; while (node.left != null) node = node.left; return node; }
public Node insert(Node node, int data) { if (node == null) return new Node(data); else { if (node.data < data) node.right = insert(node.right, data); else node.left = insert(node.left, data); return node; } }
private void inorderSucc() { if (next.right != null) { next = MinNode(next.right); } else { Node parent = next.parent; while (parent != null && parent.right == next) { next = parent; parent = next.parent; } next = parent; } }
public Node(int data, Node parent) : this(data, null, null, parent) { }
private bool InorderIter(Node node) { if (node != null) { } }
public Node(int data, Node left, Node right) { this.data = data; this.left = left; this.right = right; }