c++ - 非STL二叉搜索树搜索函数问题
问题描述
class BinarySearchTree
{
struct Node
{
T data;
Node * left;
Node * right;
Node(T key) :data(key), left(nullptr), right(nullptr) {}
};
Node * root;
int size(Node * node);
void printNode(Node*);
void deleteNode(Node*);
void insert(Node * node, Node * nodePtr);
void inorder(Node * root, void(*inorderPtr)(T &)) const;
void preorder(Node * root, void(*preorderPtr)(T &)) const;
void postorder(Node * root, void(*postorderPtr)(T &)) const;
public:
BinarySearchTree();
~BinarySearchTree();
T search(T value);
BinarySearchTree(const BinarySearchTree<T> & source);
const BinarySearchTree<T> & operator = (const Node & other);
void insert(const T);
void print();
int size();
void inorder(void(*output)(T &)) const;
void preorder(void(*preorderPtr)(T &)) const;
void postorder(void(*postorderPtr)(T &)) const;
};
template<class T>
inline T BinarySearchTree<T>::search(T value)
{
if (value == this->root){
return value;
}
else if (value < this->root)
{
if (left == nullptr){}
else
{
return left->search(value);
}
}
else if (value > this->root)
{
if (right == nullptr){}
else
{
return right->search(value);
}
}
}
错误 C2678 二进制“<”:未找到采用“T”类型左操作数的运算符(或没有可接受的转换)
错误 C2678 二进制“==”:未找到采用“T”类型左侧操作数的运算符(或没有可接受的转换)
错误 C2678 二进制“>”:未找到采用“T”类型左操作数的运算符(或没有可接受的转换)
像这样
bool handler::operator>(const weatherData & w)
{
bool temp = false;
if (w > this->testD)
{
temp = true;
}
return temp;
}
我正在尝试检索存储在 BST 中的映射,我对该特定对象有重载运算符,但由于某种原因,上面的代码会引发这些错误。如果它是 T 类型,我是否需要在我的 BST 中使用重载运算符?任何帮助都会非常感谢。
解决方案
推荐阅读
- c++ - InitializeCriticalSectionEx 不在 KERNEL32.Dll 中
- apache-spark - SparkSQL:如何对具有不同时间戳的两个时间序列数据集求和
- javascript - CouchDB 的业务逻辑
- printf - CamlinternalFormatBasics.fmt 的类型错误
- c++ - 遍历二维数组的所有子数组
- relational-database - 追逐法
- reactjs - Reactstrap 表单没有响应
- python - 使用生成器表达式时如何从字典列表中获取项目的键
- php - gd-text PHP 库不将文本包装在框中
- android - 如何到达存储/模拟/0