heaps/main.cpp
void heapify( int arr[], int n, int i )
{
	int largest = i; // Initialize largest as root
	int l = 2 * i + 1; // left = 2*i + 1
	int r = 2 * i + 2; // right = 2*i + 2

	// If left child is larger than root
	if ( l < n && arr[l] > arr[largest] )
		largest = l;

	// If right child is larger than largest so far
	if ( r < n && arr[r] > arr[largest] )
		largest = r;

	// If largest is not root
	if ( largest != i )
	{
		swap( arr[i], arr[largest] );

		// Recursively heapify the affected sub-tree
		heapify( arr, n, largest );
	}
}
// To heapify a subtree rooted with node i which is
// an index in arr[]. N is size of heap
To heapify a subtree rooted with node i which is
an index in arr[]. N is size of heap
To heapify a subtree rooted with node i which is an index in arr [] . N is size of heap
void heapify( int arr[], int n, int i )
{
	int largest = i; 
	int l = 2 * i + 1; 
	int r = 2 * i + 2; 
	if ( l < n && arr[l] > arr[largest] )
		largest = l;
	if ( r < n && arr[r] > arr[largest] )
		largest = r;
	if ( largest != i )
	{
		swap( arr[i], arr[largest] );
		heapify( arr, n, largest );
	}
}
void heapify ( int arr [ ] , int n , int i ) { int largest = i ; int l = 2 * i + 1 ; int r = 2 * i + 2 ; if ( l < n && arr [ l ] > arr [ largest ] ) largest = l ; if ( r < n && arr [ r ] > arr [ largest ] ) largest = r ; if ( largest != i ) { swap ( arr [ i ] , arr [ largest ] ) ; heapify ( arr , n , largest ) ; } }
To heapify a subtree rooted with node i which is
an index in arr[].
To heapify a subtree rooted with node i which is an index in arr [] .
// Initialize largest as root // left = 2*i + 1 // right = 2*i + 2 // If left child is larger than root // If right child is larger than largest so far // If largest is not root // Recursively heapify the affected sub-tree