/// <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(); }
public void swap(int index1, int index2) { oda temp = Nodes[index1]; Nodes[index1] = Nodes[index2]; Nodes[index2] = temp; }
/// <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); }