


#include "spec.h"

#define heapLeft(N) (N<<1)+1
#define heapRight(N) (N<<1)+2
#define heapRoot(N) (N-1)>>2
//heap need to know the array size
//because it is skipping  instead of iterate
void HeapInsert(Let data[], Let insertion, Let size){
	//min heap
	//if smaller than head
	//it take its place
	//now we insert the bigger one
	//if left is missing, just put it here
	//right is expected to be > than left
	//if insertion is smaller than left, 
	//take its place and continue insertion with left
	//else same thing with right
	//if right is missing just but it here
	Let index = 0;
	while (index < size && data[index] != 0){
		if (data[index] > insertion){
			Let tmp = data[index];
			data[index] = insertion;
			insertion = tmp;
		}
		Let left = heapLeft(index);
		if (data[left] == 0){
			data[left] = insertion;
			return;
		}
		Let right = heapRight(index);
		if (data[right] == 0){
			data[right] = insertion;
			return;
		}
		if (data[left] > insertion){
			index = left;
		}
		else if (data[right] > insertion){
			index = right;
		}
		else{
			
		}
	}
}

Let HeapPop(Let data[], Let size){
	//min heap
	//store first
	//store last
	//put zero on last
	//reinsert last
	//return first stored
	Let result = First(data);
return 0;	
}

