单选题

根据下面二叉树和给定的代码,

#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) 时,输出的结果是(    )。

A

5 3 7

B

5 7

C

2 3 4 5 6 7

D

8 7

赣ICP备20007335号-2