Question for C++ programmers

Status
Not open for further replies.

Mears

Ars Scholae Palatinae
983
Hey, I'm implementing a search feature for a BST and I want to pass into my find function two things:
1. The value I'm looking for
2. A Node pointer that will be used to cycle through the tree.

The node is a struct that holds two pointers to other node objects and also data value.

The reason for passing the Node pointer instead of creating a new one inside the find function is because I want to be able to access what it is pointing to back in the calling function.

The question is since it is a pointer, do I have to pass it as a reference parameter like, Node* &ptr, or would it be ok to just pass it as Node * ptr?

Declaration 1: bool find(int value, Node* & ptr); or
Declaration 2: bool find(int value, Node * ptr);

Desired functionality: bool x = find(Y, NodePtr);

//does some processing if the value Y wasn't found
if(!X)
{
if(NodePtr->Data > y)
{....
 
Status
Not open for further replies.