All pastes #584035 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-22 16:22 UTC
rendered paste body
#include<stdio.h>
#include<stdlib.h>

struct heap{
	int m_nheap;
	int m_max;
	void **m_a;
	};
	
typedef struct heap* PQ;

PQ PQ_New(int max){
	PQ strHeap;
	strHeap=(PQ)malloc(sizeof(struct heap));
	strHeap->nheap=0;
	strHeap->max=max;
	strHeap->a=(void**)malloc(max*sizeof(void*));
	return strHeap;
}
void UrcaValoare(PQ,int);
void Adauga(PQ h, void* x){
	//%assert(!)
	h->nheap++;
	h->a[h->nheap]=x;
	UrcaValoare(h,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;
	PQ h;	
	
	h=PQ_New(15);
	for(i=1;i<=6;i++)
		Adauga(h,&v[i]);
	
	for (i=1;i<=h->nheap;i++)
		printf("%d ",*(int*)h->a[i]);
		
	return 0;
}