Hi, could you help me with my problem? How to make a non-recusrsive function from a recursive one? This is my recursive function (function locates the node with a specified key in binary search tree)
Code:
/* Key x - searched key in the tree */
/* Bvs t - pointer to the root of the tree */
/* return value - pointer to found node, NULL if the key was not found */
Position Member ( Key x, Bvs t )
{
Position pos = NULL;
if (t == NULL) return NULL;
if (t -> key == x) return (Position)t;
if (t -> key < x) pos = Member(x, t -> right);
if (t -> key > x) pos = Member(x, t -> left);
return pos;
}
I think I should use loop and wrap all if conditions to loop and of course change bodies of conditions where function member is called, but I dont know how to implement it in C... Could you help me? Thanks....