zee15 0 Newbie Poster

ok this seems so simple, yet i cant get it down into code.

i want to do the following methods non-recursively.
here is what i have so far.
any help would be appreciated ASAP.

thanks

public boolean insert (int val)


Inserts val into the binary search tree.


public boolean member (int val)


Returns true if val is found in the tree, returns false otherwise.


what i have so far:
public void insert (int val)
{
if (root == null)
{
root = new BSTNode(val);
}


else
{
//Let the pointer be the root
BSTNode pointer = root;


//Search for where to insert the new leaf node
while (pointer != null)
{
if (pointer.getLeft()==null)
{
pointer.setLeft(new BSTNode(val));
}
else if (pointer.getRight()==null)
{
pointer.setLeft(new BSTNOde(val));
}
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.