我在写这将在一定范围内存储的所有按键作为一个字符串函数BST:在递归函数的结果存储/ BST
String rangeToString(TreeNode root,int low, int high, String result){
if(root==null) return "";
if(root.key>low)) rangeToString(root.leftChild, low, high,result);
if(root.key>=low && root.key.<=high) result+=root.key;
if(root.key<high) rangeToString(root.rightChild,low,high,result);
return result;
}
我基本上做的在遍历中,当它们在范围内时向字符串添加值。 目前它返回一个只包含根密钥的字符串。 我知道这个问题是在我的return语句,但我似乎无法得到如何实现功能没有他们。 任何人都可以指向正确的方向吗?