N
noagbodjivictor
Hi all,
I thought I knew how pointers work, but then I'm struggling with a
code, well I happen to have written last semester in my data structure
class. Why do we pass the pointer to the node of a binary tree by
reference? Isn't a pointer supposed to hold the address of an object
in memory?
Take this for example:
ItemType findMax(TreeNode* & tree) {
while(tree->right != NULL)
tree = tree->right;
return tree->info;
}
Why are we are passing the pointer tree by reference here? Don't be
too harsh, I just happen to have forgotten a little bit...
I thought I knew how pointers work, but then I'm struggling with a
code, well I happen to have written last semester in my data structure
class. Why do we pass the pointer to the node of a binary tree by
reference? Isn't a pointer supposed to hold the address of an object
in memory?
Take this for example:
ItemType findMax(TreeNode* & tree) {
while(tree->right != NULL)
tree = tree->right;
return tree->info;
}
Why are we are passing the pointer tree by reference here? Don't be
too harsh, I just happen to have forgotten a little bit...