Hello,
I have tried to create a binary search tree and perform the basic insert and print functions of it. The code for it works all right and is given below.
In all the functions, i pass a pointer by refrence as follows:
I use the syntax "type * & pointer_name". Is it the same as "pointer_type ** pointer_name". Is the first style correct? Is it the way to do it in C++11? Is the one with double asterik(pointer_type ** pointer_name) the C way of doing things?
I am only interested in what the pointer 'points to' and not the pointers own address.
I am really confused here. I use references because i have to change and update in the main function what the root(pointer) points to. Like initially when the BST is empty, it points to NULL. Then when a new first node is created, root(pointer) should point to it.
Now the root (pointer) would be pointing to root node.
So, once again, can you please try to explain how passing a pointer works without the aesterik sign? I apologize if i sound too confused, which BTW i really am :)
The rererences behave syntactically the same way as values do, but they are implemented by pointers, i.e. the value they are referring to is not copied around, only the reference (pointer) is copied.
This two declarations are different, but they will essentially do exactly the same thing.
what does it mean?
Because I am passing a pointer to bstNode hence the asterik sign
When you are passing a reference, it's almost the same thing as passing a pointer. It's just that the syntax and capabilities of references are different than those of pointers (like, you can increment a pointer, but the equivalent with references doesn't exist).