Help with C++ pointers syntax very new to me

Hello everyone, how are you doing? I am working with pointers in c++ and I have not done anything at all with them so I am learning. I have a struct with some datatypes and then the struct name with some pointers. In one of my functions I am trying to make this happen
y pointing to the root of Tree. Basically what I am asking is if I need a pointer that is not part of my to equal the null pointer of my Tree. How would I declare or syntax that. I have tried y=T->NULL but it gives me an constant compiling error. Probably because I am decalring why as pointer to my struct. How else should I decalre this? Thanks for the help

D_bashamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

D_bashamAuthor Commented:
Actually I would like to ask another question really quick that is realated. Disregard last quesiton I figured out the answer. When I compile it gives me warnings on my node ptr not being initalized why is that what should a pointer be initalized to, NULL?
0
bcladdCommented:
I am not sure I understand your question but:

struct TreeNode {
  int data;
  TreeNode *left, *right;
};

We have a type called TreeNode. It has pointers at other TreeNodes.

TreeNode *root;

Now we have a variable (called root) that points at a TreeNode. To initalize root to NULL (or 0), we just assign it:

root = NULL;

At some point you want to point y at the root of your tree. That is done with

TreeNode * y = root;

Hope this helps,
-bcl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
D_bashamAuthor Commented:
And yest that helps. That is what I was doing I just wasn't sure I was on the right track. Thank you

I am looking at the specs of this it is. Is parent and root pointer be considered the same thing?

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

bcladdCommented:
Probably not. A tree has one root (and a pointer that points at it) and every node has a parent pointer (a pointer at the node that it is the left or right child of). How you handle the parent of the root node is implementation dependent (could be NULL, for example).

-bcl
0
D_bashamAuthor Commented:
I am sorry but if you could answer one more question I know that this is not a lot of points. I am stuck on this one.

I understand what your saying how could I in syntax have y<-null[root pointer]? Thanks
0
bcladdCommented:
I do not understand what you want. Happy to answer but I don't understand.

-bcl
0
D_bashamAuthor Commented:
I think I follow this specs. What I am asking how do I get y to be the NULL Root pointer? I think that is what I mean? :)
0
bcladdCommented:
What is a NULL root pointer? A pointer at a node with a NULL child? Two NULL children? I am sorry but I don't recognize your terminology.

-bcl
0
D_bashamAuthor Commented:
Maybe I am not understanding what I am reading. Let me explain what I am seeing. There is a function that has parameters (var_1(root pointer), var_2(new node root pointer) then inside the the function is
y<-(this is an arrow) nil(which is NULL)[var_1(root pointer)]. I can't follow what this spec is saying. Doe this help? Are is still not clear? Thanks
0
bcladdCommented:
Can you post the whole function? What is the function supposed to do. I understand <- to mean assignment but [] off of a NULL (or nil) pointer doesn't make any sense to me.

Or, if you can't post the function, can you find a pointer to it on the Web? Amazon lets you search inside of books...

-bcl
0
D_bashamAuthor Commented:
I guess I should read a little further through it. what I think it is saying is a var_1 = NULL pointer to the root. Does that make since. Sorry I couldn't find anything.  
0
bcladdCommented:
What is the function called? Just curious now.
-bcl
0
D_bashamAuthor Commented:
Insert()?
0
bcladdCommented:
Okay. Are we inserting into a binary search tree (in order) or just some arbitrary tree?

Is the function recursive (does it call the same version of the function from within the function body) or not?

-bcl
0
D_bashamAuthor Commented:
Oh the before page, of the function is stuck together it is A Red and Black Tree. So it should be a NULL pointer for all nodes correct?
0
bcladdCommented:
I don't have my data structures book here with me and rb-tree insertion is not one I tend to have in memory.

A presentation of an insert routine is available at http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/red_black.html

Hope it helps,
-bcl
0
D_bashamAuthor Commented:
Thanks that will help. This isn't worth a whole lot of points but I think I have a better idea on what I need to do on this program from your first response. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.