(C++) 我正在尝试比较“猜测的数字”是否是彼此最接近的 3 个节点的乘积。以下是 BST 树中这些节点的可视化表示示例:
从上面可以看出,我怎样才能找到可能组合的所有乘积(或乘法)?
这是我目前的解决方案,正如预期的那样,它没有按预期工作:
void findproducts(struct node* root, int guess)
{
if (root != NULL) {
if (root->left != NULL && root->right != NULL) {
int trianglesum = (root->key * root->left->key * root->right->key);
printf("%d ", trianglesum);
}
//printf("%d ", root->key);
findproducts(root->left, guess);
findproducts(root->right, guess);
}
}
*我还没有实现将“猜中数字”与3个节点的所有可能乘积进行比较的功能
感谢任何帮助,如果有任何有用的资源,请分享。谢谢:)