C++ Eclipse:二进制搜索树节点->数据=变量似乎不起作用
C++ Eclipse: Binary Search Tree node->data = variable doesn't seem to work
构建成功但运行时停止在
节点->数据=投标;
在下面的函数中。所以输出成功打印到 "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;
}
}
}
因为树是空的,所以root
是一个空指针,node
也是,因为node = root;
。
从存储要插入到根节点的值开始是很奇怪的。
如果您要添加一个节点,代码应该在某处显示 new Node
,并且插入的值应该在该节点中。
找出创建它的位置留作练习。
构建成功但运行时停止在
节点->数据=投标;
在下面的函数中。所以输出成功打印到 "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;
}
}
}
因为树是空的,所以root
是一个空指针,node
也是,因为node = root;
。
从存储要插入到根节点的值开始是很奇怪的。
如果您要添加一个节点,代码应该在某处显示 new Node
,并且插入的值应该在该节点中。
找出创建它的位置留作练习。