Priority queue: Difference between revisions
Content deleted Content added
m Minor bug fix to pop function in C code - compares against root node priority in first if statement of while loop instead of the kth node |
|||
Line 273: | Line 273: | ||
} |
} |
||
char *data = h->nodes[1].data; |
char *data = h->nodes[1].data; |
||
h->nodes[1] = h->nodes[h->len]; |
h->nodes[1] = h->nodes[h->len]; |
||
int priority = h->nodes[1].priority; |
|||
h->len--; |
h->len--; |
||
i = 1; |
i = 1; |
||
while (1) { |
while (1) { |
||
k = i; |
k = i; |
||
j = 2 * i; |
j = 2 * i; |
||
if (j <= h->len && h->nodes[j].priority < |
if (j <= h->len && h->nodes[j].priority < priority) { |
||
k = j; |
k = j; |
||
} |
} |