maxBinaryHeap.c
void maxHeapify(BinaryHeap* binaryHeap, int index)
{
    int* array = binaryHeap->array;
    int left = LEFT(index);
    int right = RIGHT(index);
    
    int largest = index;
    if((left < binaryHeap->heapSize) && array[left] > array[largest])
    {
  	largest = left;
    }
    if( (right<binaryHeap->heapSize) && array[right]> array[largest])
    {
        largest = right;
    }
    if(largest != index)
    {
	swap(array, largest, index);
 	maxHeapify(binaryHeap, largest);
    }
}
/*
 Idea is all the nodes below(after) index follow maxHeap property (ie; parent is >= node)
 element at index might not follow this. So we want to push it to its position. First find larger of its two children, swap with it. 
 Then recursively run this at the changed node
*/
Idea is all the nodes below(after) index follow maxHeap property
element at index might not follow this. So we want to push it to its position. First find larger of its two children, swap with it.
Then recursively run this at the changed node
Idea is all the nodes below ( after ) index follow maxHeap property element at index might not follow this . So we want to push it to its position . First find larger of its two children swap with it . Then recursively run this at the changed node
void maxHeapify(BinaryHeap* binaryHeap, int index)
{
    int* array = binaryHeap->array;
    int left = LEFT(index);
    int right = RIGHT(index);
    int largest = index;
    if((left < binaryHeap->heapSize) && array[left] > array[largest])
    {
  	largest = left;
    }
    if( (right<binaryHeap->heapSize) && array[right]> array[largest])
    {
        largest = right;
    }
    if(largest != index)
    {
	swap(array, largest, index);
 	maxHeapify(binaryHeap, largest);
    }
}
void maxHeapify ( BinaryHeap * binaryHeap , int index ) { int * array = binaryHeap -> array ; int left = LEFT ( index ) ; int right = RIGHT ( index ) ; int largest = index ; if ( ( left < binaryHeap -> heapSize ) && array [ left ] > array [ largest ] ) { largest = left ; } if ( ( right < binaryHeap -> heapSize ) && array [ right ] > array [ largest ] ) { largest = right ; } if ( largest != index ) { swap ( array , largest , index ) ; maxHeapify ( binaryHeap , largest ) ; } }
Idea is all the nodes below(after) index follow maxHeap property (ie; parent is >= node)
element at index might not follow this.
Idea is all the nodes below ( after ) index follow maxHeap property ( ie ; parent is > = node ) element at index might not follow this .