构建成功,但运行时停止于
节点->数据=出价;
在以下功能中。因此,输出成功打印到“ Loading CSV file 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;
}
}
}
答案 0 :(得分:3)
因为树为空,所以root
为空指针,node
也为node = root;
。
通过存储要插入到根节点中的值开始是很奇怪的。
如果要添加节点,则代码应在某处显示new Node
,插入的值应在该节点中。
找出在哪里创建它作为练习。