2

I am trying to implement the MAX-HEAP-INSERT(A,key) function. It's pseudocode is:

MAX-HEAP-INSERT(A,key)
  1 A.heap-size = A.heap-size+1
  2 A[A.heap-size] = -inf 
  3 HEAP-INCREASE-KEY(A,A.heap-size,key)

Where HEAP-INCREASE-KEY(A,A.heap-size,key) is another function which i didn't have trouble understanding.

The heap is based on an array A, and as we know arrays are limited. So, when we increase the A.heap-size won't there be a problem when A.heap-size gets bigger than A.length?

4

1 回答 1

1

是的。如果发生这种情况,您必须增加数组的大小。

于 2013-07-03T13:46:28.650 回答