While looking at code of binary search tree, I came across this expression,
Node *&t;
Where Node is struct. Why t
needs to be pointer and reference at same time?
Regards
While looking at code of binary search tree, I came across this expression,
Node *&t;
Where Node is struct. Why t
needs to be pointer and reference at same time?
Regards
This is a reference to a pointer (since pointers to references are illegal in C++). This means, that t
represents some variable, which, in turn, is a pointer to Node
.
It is hard to judge, what this variable is used for without some code, but the scenario may look like the following:
void MoveNext(Node * & t)
{
t = t->next;
}
// (...)
Node * current = head;
MoveNext(current);
// Now current points to second item