Woman ExtractMax() { Woman maxV = A.get(1); A.set(1, A.get(BinaryHeapSize)); BinaryHeapSize--; // virtual decrease shiftDown(1); return maxV; }
void BuildBinaryHeap(Woman[] array) { // the O(n) version, array is 0-based BinaryHeapSize = array.length; A = new Vector<Woman>(); A.add(new Woman()); // dummy, this BinaryHeap is 1-based for (int i = 1; i <= BinaryHeapSize; i++) // copy the content A.add(array[i - 1]); for (int i = parent(BinaryHeapSize); i >= 1; i--) shiftDown(i); }
void Update(Woman mother) { Woman temp; int i = getNameIndex(mother.name); temp = A.get(i); temp.dilation = A.get(i).dilation + mother.dilation; temp.name = A.get(i).name; temp.order = A.get(i).order; A.set(i, temp); shiftUp(i); shiftDown(i); }
void Delete(String motherName) { int i = getNameIndex(motherName); A.set(i, A.get(BinaryHeapSize)); A.remove(BinaryHeapSize); B.remove(motherName); BinaryHeapSize--; if ((i - 1) != BinaryHeapSize) { shiftUp(i); shiftDown(i); } }