void BinarySearchTree::insert(int d)
{
tree_node* t = new tree_node;
tree_node* parent;
t->data = d;
t->left = NULL;
t->right = NULL;
parent = NULL;
// is this a new tree?
if(isEmpty()) root = t;
else
{
//Note: ALL insertions are as leaf nodes
tree_node* curr;
curr = root;
// Find the Node's parent
while(curr)
{
parent = curr;
if(t->data > curr->data) curr = curr->right;
else curr = curr->left;
}
if(t->data < parent->data)
parent->left = t;
else
parent->right = t;
}
}
问题:
为什么我需要为tree_node* t分配内存;使用 new 但不用于tree_node* 父级;?
究竟什么是 tree_node* 它在内存中是什么样子的,它有什么作用?
有人可以向我解释 -> 运算符及其工作原理吗?