根据下面二叉树和给定的代码,
#include <iostream>
using namespace std;
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
TreeNode* search(TreeNode* root, int val) {
cout << root->val << " ";
if (root == NULL || root->val == val) return root;
if (val < root->val)
return search(root->left, val);
else
return search(root->right, val);
}
给定以下二叉搜索树,调用函数 search(root,7) 时,输出的结果是( )。
5 3 7
5 7
2 3 4 5 6 7
8 7