pq[]
to hold indices, add an array keys[]
to hold the key
values, add an array pq[]
that is the inverse of pq[]
- qp[i]
gives the position of i
in pq[]
(the index such that pq[j]
is i
). Then modify the code in Algorithm 2.6 to maintain these data structures. Use the convention that qp[i] = -1
if i
is not on the queue, and include a method contains()
that tests this condition. You need to modify the helper methods exchange()
and less()
but not sink()
or swim()
.