Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node dequeue(Node heap[])
- {
- if(array_size == 0)
- {
- printf("heap is empty\n");
- return -123456789;
- }
- Node t;
- t = heap[0];
- Swap(&heap[0],&heap[array_size-1]);
- array_size = array_size-1;
- heapifyroot(heap);
- return t;
- }
- void heapifyroot(Node heap[])
- {
- int i = 0;
- while(i< (array_size)/2 && (heap[i].priority <= heap[2*i+1].priority || heap[i].priority <= heap[2*i+2].priority))
- {
- if(heap[2*i+1].priority < heap[2*i+2].priority)
- {
- Swap(&heap[0],&heap[2*i+2]);
- i = 2*i+2;
- }
- else if(heap[2*i+1].priority > heap[2*i+2].priority)
- {
- Swap(&heap[0],&heap[2*i+1]);
- i = 2*i+1;
- }
- else
- {
- if(heap[2*i+1].priority2 > heap[2*i+2].priority2)
- {
- Swap(&heap[0],&heap[2*i+2]);
- i = 2*i+2;
- }
- else
- {
- Swap(&heap[0],&heap[2*i+1]);
- i = 2*i+1;
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement