Question: * * if ( temp < heap [ child ] ) { heap [ i ] = heap [ child ] ; } else break;

** if(temp < heap[child]){ heap[i]= heap[child]; }else break; i = child; } heap[i]= temp; } private int maxChild(int i){ int leftChild = kthChild(i,1); int rightChild = kthChild(i,2); return heap[leftChild]>heap[rightChild]?leftChild:rightChild; **
The Ternary operation shown above is from the method shown below, please help convert this ternary operation into a if and else statement. I Have been stuck on this for a few days know on how to do this, with out destroying the logic, that then breaks my code.
private void heapifyDown(int i){
int child;
int temp = heap[i];
while(kthChild(i,1)< heapSize){
child = maxChild(i);
if(temp < heap[child]){ heap[i]= heap[child]; }else break; i = child; } heap[i]= temp; } private int maxChild(int i){ int leftChild = kthChild(i,1); int rightChild = kthChild(i,2); return heap[leftChild]>heap[rightChild]?leftChild:rightChild;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!