C++ Eclipse:二进制搜索树节点->数据=变量似乎不起作用
生成成功,但运行时在停止 节点->数据=投标 在下面的函数中。因此,输出成功打印出来,直到加载CSV文件888 cout语句为止。我不确定是什么阻止它运行该代码C++ Eclipse:二进制搜索树节点->数据=变量似乎不起作用,c++,data-structures,binary-tree,binary-search-tree,binary-search,C++,Data Structures,Binary Tree,Binary Search Tree,Binary Search,生成成功,但运行时在停止 节点->数据=投标 在下面的函数中。因此,输出成功打印出来,直到加载CSV文件888 cout语句为止。我不确定是什么阻止它运行该代码 void BinarySearchTree::Insert(Bid bid) { // FIXME (2a) Implement inserting a bid into the tree cout << "Loading CSV file 333" << endl; Node* node = root;
void BinarySearchTree::Insert(Bid bid) {
// FIXME (2a) Implement inserting a bid into the tree
cout << "Loading CSV file 333" << endl;
Node* node = root;
cout << "Loading CSV file 888" << endl;
node->data = bid;
cout << "Loading CSV file 777" << endl;
if (root == NULL){
//root->data = bid;
//root->left = 0;
//root->right = 0;
root = node;
node->left = NULL;
node->right = NULL;
cout << "Loading CSV file 444" << endl;
}
else
{
cout << "Loading CSV file 666" << endl;
Node* cur;
cur = root;
while (cur != NULL){
if (strToDouble2(node->data.bidId) < strToDouble2(cur->data.bidId)){
if (cur->left == NULL){
cur->left = node;
cur = NULL;
}
else{
cur = cur->left;
}
}
else
if (cur->right == 0){
cur->right = node;
cur = NULL;
}
else{
cur = cur->right;
}
node->left = NULL;
node->right = NULL;
cout << "Loading CSV file 5555" << endl;
}
}
}
因为树是空的,所以root是空指针,node也是空指针,因为node=root 首先将要插入的值存储在根节点中是非常奇怪的。 如果您要添加一个节点,代码应该在某个位置显示new node,插入的值应该在该节点中 作为练习,找出在哪里创建它