Пример #1
0
        public TreeNodeWithParentsLink <T> Inordrsucc(TreeNodeWithParentsLink <T> current)
        {
            if (current.right == null)
            {
                if (current != null)
                {
                    current = current.parents;
                    while (current.left != null)
                    {
                        current = current.right;
                    }
                }
                return(current);
            }

            TreeNodeWithParentsLink <T> x    = current.parents;
            TreeNodeWithParentsLink <T> node = current;

            while (x != null && x.left != node)
            {
                node = x;
                x    = x.parents;
            }

            return(x);
        }
Пример #2
0
        new public void Add(T data)
        {
            TreeNodeWithParentsLink <T> current = new TreeNodeWithParentsLink <T>(data);


            if (root == null)
            {
                root = new TreeNodeWithParentsLink <T>(data);
                TreeRecords.Enqueue(root);
            }
            else
            {
                if (TreeRecords.Count > 0)
                {
                    TreeNodeWithParentsLink <T> node = TreeRecords.Peek();

                    if (node.right != null && node.left != null)
                    {
                        TreeRecords.Dequeue();
                        TreeRecords.Enqueue(node.right);
                        TreeRecords.Enqueue(node.left);
                        node = TreeRecords.Peek();
                    }



                    if (node.right == null)
                    {
                        node.right         = current;
                        node.right.parents = node;
                    }

                    else if (node.left == null)
                    {
                        node.left         = current;
                        node.left.parents = node;
                    }
                }
            }
        }