对于 BST,我想在 [a,b] 中找到节点的值,从最大值到最小值。我能想到的最简单的方法如下:
void printRange(BSTNode<Key,E>* root,int lowValue,int highValue) const
{
    if(root==NULL) return;
    printRange(root->right(),lowValue,highValue);
    if(root->key()>=lowValue&&root->key()<=highValue)
        cout<<root->key()<<" ";
    printRange(root->left(),lowValue,highValue);
}
但我想知道是否有一种方法可以打印出访问的节点较少的这些值?