Пример #1
0
        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);
        }
Пример #2
0
        //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
        }
Пример #3
0
 public Node(int data, Node left, Node right, Node parent)
 {
     this.data = data;
     this.left = left;
     this.right = right;
     this.parent = parent;
 }
Пример #4
0
 private Node MinNode(Node node)
 {
     if (node == null)
         return node;
     while (node.left != null)
         node = node.left;
     return node;
 }
Пример #5
0
 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;
     }
 }
Пример #6
0
 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;
     }
 }
Пример #7
0
 public Node(int data, Node parent)
     : this(data, null, null, parent)
 {
 }
Пример #8
0
 private bool InorderIter(Node node)
 {
     if (node != null)
     { }
 }
Пример #9
0
 public Node(int data, Node left, Node right)
 {
     this.data = data;
     this.left = left;
     this.right = right;
 }