29 Aug, 2013, Tyche wrote in the 21st comment:
Votes: 0
Davenge said:
Because the code he shared required a capacity?


That heap is an array of pointer, so…
/* instead of this */
if (q->size >= q->capacity) {
DEBUG("Priority Queue is full. Cannot add another element .");
return;
}
/* do this … doubles capacity every time */
if (q->size >= q->capacity) {
q->capacity *= 2;
q->data = realloc(q->data, q->capacity * sizeof(*(q->data)));
NP_CHECK(q->data);
}
29 Aug, 2013, Davenge wrote in the 22nd comment:
Votes: 0
And that's the "realloc" nonsense I was talking about Quix
29 Aug, 2013, quixadhal wrote in the 23rd comment:
Votes: 0
I suppose. I've never implemented a heap using an array. I've always used node pointers, much like a binary tree.
20.0/23