示例#1
0
文件: Heap.cs 项目: TheCCO2018/Shoppy
        public void MoveToDown(int index)
        {
            int      largerChild;
            HeapNode top = heapArray[index];

            while (index < currentSize / 2)
            {
                int leftChild  = 2 * index + 1;
                int rightChild = leftChild + 1;
                //Find larger child
                if (rightChild < currentSize && heapArray[leftChild].Value.SalePrice < heapArray[rightChild].Value.SalePrice)
                {
                    largerChild = rightChild;
                }
                else
                {
                    largerChild = leftChild;
                }
                if (top.Value.SalePrice >= heapArray[largerChild].Value.SalePrice)
                {
                    break;
                }
                heapArray[index] = heapArray[largerChild];
                index            = largerChild;
            }
            heapArray[index] = top;
        }
示例#2
0
文件: Heap.cs 项目: TheCCO2018/Shoppy
        public HeapNode RemoveMax() // Remove maximum value HeapNode
        {
            HeapNode root = heapArray[0];

            heapArray[0] = heapArray[--currentSize];
            MoveToDown(0);
            return(root);
        }
示例#3
0
文件: Heap.cs 项目: TheCCO2018/Shoppy
        public bool Insert(Product value)
        {
            if (currentSize == maxSize)
            {
                return(false);
            }
            HeapNode newHeapDugumu = new HeapNode(value);

            heapArray[currentSize] = newHeapDugumu;
            MoveToUp(currentSize++);
            return(true);
        }
示例#4
0
文件: Heap.cs 项目: TheCCO2018/Shoppy
        public void MoveToUp(int index)
        {
            int      parent = (index - 1) / 2;
            HeapNode bottom = heapArray[index];

            while (index > 0 && heapArray[parent].Value.SalePrice < bottom.Value.SalePrice)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }