Insert Code
void insert(Object o) {
assert(!isFull());
size++;
newPos =
percolateUp(size,o);
Heap[newPos] = o;
}
int percolateUp(int hole,
Object val) {
while (hole > 1 &&
val < Heap[hole/2])
Heap[hole] = Heap[hole/2];
hole /= 2;
}
return hole;
}
runtime:
Previous slide
Next slide
Back to first slide
View graphic version