Teen Programmers Unite  
 

 

Return to forum top

return Tree Node pointer back to void main()

Posted by gazza [send private reply] at July 06, 2002, 01:54:25 PM

ok what im doing here with the code below is searching for a
customers name as you can see once the name is found the ID
and the address of that customer displays ..now how can i return
the node pointer back to void main to display all of the customers
details

that way by returning the node pointer i can write out the position
where the customer is found rather thatn writting it out in the
function ........

how do i return a node pointer back to void main ?


char BinaryTree::WordSearch (TreeNode *nodePtr,char* wSearchCustName){

if (nodePtr != 0) {

//Compares the two string word in the tree and the word being searched for
if (strcmp(word,nodePtr->CustName) == 0){
cout <<"ID:" <<nodePtr->code << " ";
cout <<" Word:"<<nodePtr->CustName <<" ";
cout <<" def':"<<nodePtr->CustAdd <<'\n';

return true;
}

//Traverse the left branch, then the right branch
this->WordSearch(nodePtr->leftChild,word);
this->WordSearch(nodePtr->rightChild,word);

}return false;
}

Posted by Psion [send private reply] at July 06, 2002, 02:43:24 PM

You're saying that you don't know how to return a pointer from a function?

Posted by sphinX [send private reply] at July 06, 2002, 10:07:46 PM

TreeNode *Myfunction(...)
{
TreeNode *correctNode;
/* insert search code here */
return correctNode;
}

This will return the pointer to the calling function.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.