Want
Want

Reputation: 820

Max Priority queue based on max-heap

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?

Upvotes: 2

Views: 332

Answers (1)

Will
Will

Reputation: 75673

Yes. If this happens you have to increase the size of your array.

Upvotes: 1

Related Questions