Originally posted by 12520428
View Post
PHP Code:
TNode *searchNode(tree t,tagTNode* x)
{
TNode *p; // dùng để làm gì
if(t)
{
if(x==p->key) return t; // chưa cấp phát cho p sao dùng được p->key
if(t->key > x) // x là 1 con trỏ kiểu node mà đem so sánh với 1 giá trị int ???
return searchNode(t->pLeft,x);
if(t->key <x)
return searchNode(t->pRight,x);
}
return NULL;
}
PHP Code:
Node *SearchNode(TREE T, int x)
{
Node *p = T;
while (p != NULL)
{
if (x == p->key)
{
return p;
}
else if (x < p->key)
{
p = p->pLeft;
}
else
{
p = p->pRight;
}
}
return NULL;
}
Leave a comment: