Chat on IRC |
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.
Register as a new user | |||||