Returning a Tree node back to void main()

This is a discussion on Returning a Tree node back to void main() within the C++ Programming forums, part of the General Programming Boards category; ok what im doing here with the code below is searching for a customers name as you can see once ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    2

    Question Returning a Tree node back to void main()

    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 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;
    }

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    You could either try and return a Nodeptr/NULL back up the stack or pass a pointer to a Nodeptr (Nodeptr**) into the function and assign either the found node or NULL to it after de-referencing it.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Code:
    TreeNode *BinaryTree::WordSearch (TreeNode *nodePtr,char* wSearchCustName)
    // Return NULL if not found, or else pointer to node

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM
  5. binary tree node structure
    By Kirsten in forum C Programming
    Replies: 2
    Last Post: 04-26-2002, 08:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21