Use a suitably constructed heap.