コード例 #1
0
        public void MoveToUp(int index)
        {
            int      parent = (index - 1) / 2;
            HeapNode bottom = heapArray[index];

            while (index > 0 && heapArray[parent].Key < bottom.Key)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }
コード例 #2
0
        public bool Insert(int value)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapNode newNode = new HeapNode(value);

            heapArray[currentSize] = newNode;
            MoveToUp(currentSize);
            currentSize++;
            return(true);
        }