I was trying to quickly write a function that finds the tree node with the lowest value for one of its unsorted members. Thus:-
There are no duplicate values in the tree. Needless to say, this doesn't work and I'm bogged down.
// Inputs: tree node to search, optional limiter value (node returned must have ulCode > *ulPrevLowest)
t_freqtree *TreeLowest(t_freqtree *root, unsigned long *ulPrevLowest)
t_freqtree *cmpleft, *cmpright;
// Search everywhere else first, tree isn't sorted by ulCode!
cmpleft = TreeLowest(root->left, ulPrevLowest);
cmpright = TreeLowest(root->right, ulPrevLowest);
// There can only be one
if (cmpleft && cmpright)
cmpleft = (cmpleft->ulCode < cmpright->ulCode) ? cmpleft : cmpright;
cmpleft = (cmpleft) ? cmpleft : cmpright;
if (root->ulCode <= *ulPrevLowest && cmpleft)
if (cmpleft->ulCode > *ulPrevLowest)
return (cmpleft->ulCode < root->ulCode) ? cmpleft : root;