Ejemplo n.º 1
0
 /// <summary>
 /// 弹出队头
 /// </summary>
 public void Pop()
 {
     if (this.heapLength == 0)
     {
         throw new OverflowException("队列为空时不能出队");
     }
     // 维护堆的属性
     heapLength--;
     this.swap(0, heapLength);
     MaxHeap <T> .heapAdjustFromTop(this.buffer, 0, this.heapLength);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 将元素排队
        /// </summary>
        /// <param name="obj">要放入的元素</param>
        public void Push(T obj)
        {
            // 如果队列不够尺寸就拓展
            if (this.heapLength == this.buffer.Length)
            {
                this.expand();
            }
            // 维护堆的属性
            this.buffer[heapLength] = obj;
            MaxHeap <T> .heapAdjustFromBottom(this.buffer, this.heapLength);

            this.heapLength++;
        }