Thread: Binary Tree beginner

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    Binary Tree beginner

    Hello there everybody. We were just given an assignment before we were sent out on vacation for the thanksgiving holiday. I understand mostly everything the only thing I'm having trouble with is how to send a pointer to a function that is not a class. Simply just a regular user defined function. The function we have is listed as such


    isertnewnode(node *&p, int x);

    now I understand everything that is happening here the only problem I'm having is what do I send to this function for evaluation. right now I'm trying to send "root" and some integer to the function for evaluation. Does anybody out there know where to go with this bit of code at all

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    All you gave was a function prototype. We might be able to help if you posted more code. Be sure to use code tags.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    More code should clear it up, but it looks like the reference (the &) means that the pointer will be updated inside the function. So instead of returning a pointer to the new node, this function just sets the parameter to the new value. That's not how I would have done it, but here is how you can use it:
    Code:
    isertnewnode(node *&p, int x);
    
    ...
    
    node * root = 0;
    isertnewnode(root, 3);
    // root should now be something other than 0.
    Of course, this might be completely off depending on the code inside that function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM