コード例 #1
0
 /// <summary>
 /// Add a new item to heap, enlarging the array if needed
 /// </summary>
 /// <returns>void</returns>
 public void add(oda item)
 {
     EnlargeIfNeeded();
     Nodes[Size] = item;
     Size++;
     heapifyUp();
 }
コード例 #2
0
        public void swap(int index1, int index2)
        {
            oda temp = Nodes[index1];

            Nodes[index1] = Nodes[index2];
            Nodes[index2] = temp;
        }
コード例 #3
0
        /// <summary>
        /// Removes the minimum element at the root of the tree
        /// </summary>
        /// <returns>Int value of minimum element</returns>
        /// <exception cref="">InvalidOperationException when heap is empty</exception>
        public oda pop()
        {
            if (Size == 0)
            {
                throw new InvalidOperationException("Heap is empty");
            }

            oda item = Nodes[0];

            Nodes[0] = Nodes[Size - 1];
            Size--;
            heapifyDown();
            return(item);
        }