Hi All,
I have below function:
//************************************************** *******
struct Tnode {
std::string word;
int count;
Tnode *next;
};
Tnode* new_Tnode(std::string const &word) {
Tnode *node = new Tnode;
node->word = word;
node->count = 1;
node->next = 0;
return node;
}
void add_word(Tnode *&root, std::string const &word) {
Tnode *node = root;
while (1) {
Tnode *&next = node->next; //?????
if (next==0) {
next = new_Tnode(word);
break;
} else
node = next;
}
}
}
.....
//************************************************** ************************
**************
What's the diffrence for "Tnode *&next = node->next;" and "Tnode *next =
node->next;" ?
The same is: why pass Tnode *&root, not Tnode *root.
I tried remove & from above 2 sentences, and the program didn't work.
Thanks.
Franklin