Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_SIZE 500
- int array_size = 0;
- typedef struct
- {
- int priority,value;
- }Node;
- void initialize(Node heap[])
- {
- array_size = 0;
- return;
- }
- void heapify(Node heap[], int i /*index*/)
- {
- int j;
- Node temp;
- j = i/2;
- while (i > 0 && heap[j].priority < heap[i].priority)
- {
- temp = heap[j];
- heap[j] = heap[i];
- heap[i] = temp;
- i=j;
- j/=2;
- }
- return;
- }
- void enqueue(Node heap[],int priority,int value)
- {
- if(array_size == MAX_SIZE)
- {
- printf("you reached max size");
- return;
- }
- heap[array_size].priority = priority;
- heap[array_size].value = value;
- array_size++;
- heapify(heap,array_size);
- return;
- }
- int main()
- {
- Node heap[MAX_SIZE];
- initialize(heap);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement