Skip to content

Instantly share code, notes, and snippets.

@atoye1
Created December 16, 2021 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoye1/541a6e36b8b9a10a1ee5d29bc603a185 to your computer and use it in GitHub Desktop.
Save atoye1/541a6e36b8b9a10a1ee5d29bc603a185 to your computer and use it in GitHub Desktop.
typedef struct {
int heap[MAX_DATA];
int heap_size;
} HeapType;
int deleteHeap(HeapType *h){
int parent, child;
int item, temp;
item = h->heap[0];
temp = h->heap[(h->heap_size)--];
parent = 1;
child = 2;
while(child <= h->heap_size){
if ((child < h->heap_size) && (h->heap[child] > h->heap[child+1]))
child++;
if (temp <= h->heap[child])
break;
h->heap[parent] = h->heap[child];
parent = child;
child *= 2;
}
h->heap[parent] = temp;
return item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment