[ create a new paste ] login | about

Link: http://codepad.org/Brix848e    [ raw code | output | fork ]

C++, pasted on Nov 7:
void buildHeap(int *heap1, int CAP)
{
	for(int j=CAP; j>0; j--)
	{
		for(int i=((CAP-1)/2); i>=0; i--)
		{
			heapify(heap1, CAP, i);
		}
	}
};

void heapify(int *heap, int CAP, int i)
{
	int l, r, largest;
	l=2*i+1;
	r=2*i+2;
	
	if(r==CAP)
	{
		largest=l;
		r=l;
	}
	
	if(heap[r]>heap[i])
	{
		int temp;
		temp=heap[i];
		heap[i]=heap[r];
		heap[r]=temp;
	}
	
	if(heap[l]>heap[i])
	{
		int temp;
		temp=heap[i];
		heap[i]=heap[l];
		heap[l]=temp;
	}
	return;
};


Output:
1
2
3
In function 'void buildHeap(int*, int)':
Line 7: error: 'heapify' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: