Example #1
0
            private void Add(TreapNode node, ref TreapNode currentNode)
            {
                if (currentNode == null)
                {
                    currentNode = node;
                    currentNode.UpdateCount();
                    return;
                }

                if (currentNode.Priority > node.Priority)
                {
                    if (currentNode.Value > node.Value)
                    {
                        this.Add(node, ref currentNode.left);
                    }
                    else
                    {
                        this.Add(node, ref currentNode.right);
                    }

                    currentNode.UpdateCount();
                    return;
                }

                this.Split(currentNode, node.Value, ref node.left, ref node.right);
                currentNode = node;
                currentNode.UpdateCount();
            }
Example #2
0
            private void Split(TreapNode node, int value, ref TreapNode left, ref TreapNode right)
            {
                if (node == null)
                {
                    left  = null;
                    right = null;

                    return;
                }

                if (value > node.Value)
                {
                    left = node;
                    this.Split(node.right, value, ref node.right, ref right);
                    left.UpdateCount();
                }
                else
                {
                    right = node;
                    this.Split(node.left, value, ref left, ref node.left);
                    right.UpdateCount();
                }
            }