C++ Eclipse:二叉搜索树节点>数据=变量似乎不起作用

C++ Eclipse: Binary Search Tree node->data = variable doesn't seem to work

本文关键字:数据 变量 不起作用 gt Eclipse 搜索 树节点 搜索树 C++      更新时间:2023-10-16

构建成功,但运行时停止在

节点>数据 = 出价;

在以下函数中。因此,输出成功打印到"加载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;
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 = root;年以来node也是如此。

从存储要插入根节点的值开始是非常奇怪的。
如果要添加节点,代码应显示new Node某处,并且插入的值应位于该节点中。

弄清楚在哪里创建它作为练习。