原题题目
代码实现
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
#define MAX 5000
struct TreeNode* searchBST(struct TreeNode* root, int val)
{
if(!root)
return NULL;
int top = -1,rear = -1;
struct TreeNode* queue[MAX];
struct TreeNode* position;
queue[++rear] = root;
while(rear != top)
{
position = queue[++top];
if(position->val == val)
return position;
if(position->left)
queue[++rear] = position->left;
if(position->right)
queue[++rear] = position->right;
}
return NULL;
}