#include<iostream>
#include<malloc.h>
using namespace std;
struct BSTree {
int data;
BSTree* left;
BSTree* right;
};
void insert_Node(BSTree*& root, int n) {
if (root == NULL) {
root = new BSTree();
root->data = n;
root->left = NULL;
root->right = NULL;
}
else {
if (n <= root->data) {
insert_Node(root->left, n);
}
else {
insert_Node(root->right, n);
}
}
}
void preOder(BSTree* root) {
if (root == NULL) {
return;
}
else {
cout << root->data << " ";
preOder(root->left);
preOder(root->right);
}
}
int main() {
BSTree* root = NULL;
int n;
cin >> n;
while (n != 0) {
insert_Node(root, n);
cin >> n;
}
preOder(root);
return 0;
}
运行结果及详细报错内容
代码没有问题,我就是不理解那一句void insert_Node(BSTree*& root, int n)
里面*&这个用法,有没有同学指导下
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
他那个已经是指针,为啥还要取地址符号