"Ridimz" <ri****@SPAMyahooFREE.com> wrote in message
news:dr******************@twister.southeast.rr.com ...
I have implemented a binary search tree and am interested in displaying
all keys less than a certain value. I understand how to approach this task if
the searchValue is equal to root.key(). Otherwise I'm lost. Any
suggestions or examples would be greatly appreciated
Thanks,
Ridimz
void output_all_less_than(const T& t, std::ostream& os = std::cout, const
Node *pNode = NULL) const
{
if(!pNode)
{
if(!m_nodes.empty()) pNode = &m_nodes.front();
else return;
}
if(Pred()(t, pNode->m_data) || t == pNode->m_data)
{
if(pNode->m_pLeft) output_all_less_than(t, os, pNode->m_pLeft);
}
else
{
if(pNode->m_pLeft) output_all_less_than(t, os, pNode->m_pLeft);
os << pNode->m_data << ' ';
if(pNode->m_pRight) output_all_less_than(t, os, pNode->m_pRight);
}
}
HTH,
Stuart.