当我尝试使用下面第 15 行中的指针变量 *temp 创建一个新的 Node 对象时,我遇到了分段错误。我对 c++ 以及双指针的工作方式仍然很陌生,尤其是与 & 结合使用时。谢谢你的帮助。
void bst::insert(int n) {
Node **temp;
Node *r, *parent;
// Tree is empty
if (root == NULL) {
root = new Node;
root->parent = NULL;
root->value = n;
root->left = NULL;
root->right = NULL;
root->isBlack = true;
} else {
r = root;
// Create a node with the given value, n
(*temp) = new Node;
(*temp)->value = n;
(*temp)->left = NULL;
(*temp)->right = NULL;
(*temp)->isBlack = false;