# Thread: how to make a non-recursive function from recursive

1. ## how to make a non-recursive function from recursive

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....

2. Try mapping out on paper what would happen for a couple of (non-trivial) trees and search keys. That will give you an insight as to what needs to be converted into loops, and what the end conditions are.

I'm not going to give a more specific answer than that, as this strikes me as homework. Regardless of whether it's homework, you will benefit more if you work out the solution for yourself.

This is one of those problems that initially looks hard but, once you have solved it, you realise it's easy and you can use the approach to solve other problems.