rendered paste body
#include<stdio.h>
#include<stdlib.h>
struct heap{
int nheap;
int max;
void **a;
}
struct heap* PQ;
PQ PQ_New(int max){
h=(PQ)malloc(sizeof(struct heap));
h->nheap=0;
h->max=max;
h->a=(void**)malloc(max*sizeof(void*));
return h;
}
void Adauga(PQ h, void* x){
//%assert(!)
nheap++;
h->a[nheap]=x;
UrcaValoare(h,nheap);
}
void UrcaValoare(PQ h, int poz){
if (poz/2>1 && h->a[poz]>h->a[poz/2])
{
interschimba(h->a[poz], h->a[poz/2]);
poz=poz/2;
}
}
int main(){
int v[30], i ;
v[1]=2; v[2]=9; v[3]=5;
v[4]=3; v[5]=6; v[6]=10;
h=PQ_New(15);
for(i=1;i<=6;i++)
Adauga(h,&v[i]);
for (i=1;i<=nheap;i++)
printf("%d ",*(int*)h->a[i]);
return 0;
}