I am reading a book about Binary Search Tree and something weird came up. I came across the following declaration in a function parameter.
BinaryNode * & t
What does it mean? Pointer of the address of t?
For context, this is the code where I saw this. The private insert function is a helper function for public insert function, and private insert function looks for the right place to insert using recursion.
class BST
{
public:
void insert(const Comparable & item)
private:
BinaryNode *root;
struct BinaryNode
{
Comparable element;
BinaryNode *left;
BinaryNode *right;
BinaryNode(const Comparable & theElement, BinaryNode *lt, BinaryNode *rt) :
element(theElement), left(lt), right(rt) {}
}
void insert(const Comparable & item, BinaryNode * & t) const;
};
In your expression
BinaryNode * & t)so
tis reference to pointer of BinaryNode class.You are confused
ampersand &operator in c++. that give address of an variable. but syntax is different.ampersand &in front of some of variable like below:But following way is for reference variable (its simple not pointer):
and your is like below: