Exemple #1
0
        // Support methods
        private void DownHeap(int element)
        {
            SearchResult s       = data.SearchElement(element);
            TreapElement current = (TreapElement)s.previous;
            bool         isLeft;

            while (!HeapReq(current))
            {
                isLeft = (current.left == s.found) ? true : false;

                if (isLeft)
                {
                    current.RightRotation();
                }
                else
                {
                    current.LeftRotation();
                }

                s       = data.SearchElement(element);
                current = (TreapElement)s.previous;
            }
        }
Exemple #2
0
        private void UpHeap(int element)
        {
            SearchResult s = data.SearchElement(element);
            TreapElement current = (TreapElement)s.found;
            TreapElement l = (TreapElement)current.left, r = (TreapElement)current.right;

            while (current.left != null && current.right != null)
            {
                if (l != null && l.heap <= r.heap)
                {
                    current.RightRotation();
                }
                else
                {
                    current.LeftRotation();
                }


                s       = data.SearchElement(element);
                current = (TreapElement)s.found;
                l       = (TreapElement)current.left;
                r       = (TreapElement)current.right;
            }
        }