mercredi 25 mars 2015

Find the lowest leaf in a binary tree


i'm trying to compare all leafs to return the lowest value of a tree, I don't have main function just a script to insert values so unfortunately I can't debug it.



tpNoArvore * findLowest(tpNoArvore * pNo){
tpNoArvore * left;
tpNoArvore * right;
tpNoArvore * res;

if (!pNo) return NULL; /* if */

left = findLowest(pNo->pNoL);
right = findLowest(pNo->pNoR);
if(isLeaf(pNo))
return pNo;
} /* if */

if(!left){
return right;
} /* if */

if(!right){
return left;
} /* if */


return (left->Valor < right->Valor) ? left : right ;

}


So, basically what i'm trying to achieve here is to compare the two sides of each node to find the lowest.




Aucun commentaire:

Enregistrer un commentaire