char UpwardFloorRunHeap::pop() { int frSize = floorRequestHeap->getSize(); int hcSize = hallCallHeap->getSize(); if (frSize == 0 && hcSize == 0) { throw EmptyHeapException(); } else if (frSize == 0) { return hallCallHeap->pop(); } else if (hcSize == 0) { return floorRequestHeap->pop(); } char frTop = floorRequestHeap->peek(); char hcTop = hallCallHeap->peek(); char temp = (frTop < hcTop) ? frTop : hcTop; /* Remove duplicates from the top of the heap */ while (this->hallCallHeap->getSize() > 0 && this->hallCallHeap->peek() == temp) { this->hallCallHeap->pop(); } while (this->floorRequestHeap->getSize() > 0 && this->floorRequestHeap->peek() == temp) { this->floorRequestHeap->pop(); } return temp; }
char DownwardFloorRunHeap::pop() { int frSize = floorRequestHeap->getSize(); int hcSize = hallCallHeap->getSize(); if (frSize == 0 && hcSize == 0) { throw EmptyHeapException(); } else if (frSize == 0) { return hallCallHeap->pop(); } else if (hcSize == 0) { return floorRequestHeap->pop(); } char frTop = floorRequestHeap->peek(); char hcTop = hallCallHeap->peek(); char temp = (frTop > hcTop) ? frTop : hcTop; while (floorRequestHeap->getSize() > 0 && floorRequestHeap->peek() == temp) { floorRequestHeap->pop(); } while (hallCallHeap->getSize() > 0 && hallCallHeap->peek() == temp) { hallCallHeap->pop(); } return temp; }
int getMinimalElement() const { if (!root) { throw EmptyHeapException(); } return root->getKey(); }
int extractMin() { if (!root) { throw EmptyHeapException(); } int result = root->getKey(); INode *newRoot = meld_(root->getLeft(), root->getRight()); root->getLeft() = root->getRight() = NULL; delete root; root = newRoot; --size_; return result; }
char DownwardFloorRunHeap::peek() const { int frSize = floorRequestHeap->getSize(); int hcSize = hallCallHeap->getSize(); if (frSize == 0 && hcSize == 0) { throw EmptyHeapException(); } else if (frSize == 0) { return hallCallHeap->peek(); } else if (hcSize == 0) { return floorRequestHeap->peek(); } char frTop = floorRequestHeap->peek(); char hcTop = hallCallHeap->peek(); return (frTop > hcTop) ? frTop : hcTop; }
virtual T peek() { if (this->getSize() == 0) throw EmptyHeapException(); return this->data->front(); }