二叉树搜索不起作用

时间:2015-04-28 01:15:54

标签: c++

template<class T>
class Tree {
  public:
    Tree(TreeNode *rootPtr = NULL)
    {
        this->rootPtr = rootPtr;
    };
    TreeNode<T> *search(string x);
    bool insert(T x);
    TreeNode * remove(T x);
    TreeNode *getRoot(){ return rootPtr; };
    Tree getLeftSubtree(); Tree getRightSubtree();
    bool isEmpty(){ return rootPtr == NULL; };

private:
    TreeNode<T> *rootPtr;
};

我收到此错误

C2955: 'TreeNode' : use of class template requires template argument list

TreeNode类是:

template <class T>
class TreeNode{
    T data; // different data type for other apps
    TreeNode<T> *left; // a pointer to left child
    TreeNode<T> *right; // a pointer to right child
  public:
    TreeNode(T x = 0, TreeNode *left = NULL,TreeNode *right = NULL)
    {
        data = x;
        this->left = left;
        this->right = right;
    };
    T getData() { return data; };
    TreeNode<T> *getLeft() { return left; };
    TreeNode<T> *getRight() { return right; };
    void setData(T x) { data = x; };
    void setLeft(TreeNode *ptr) { left = ptr; };
    void setRight(TreeNode *ptr) { right = ptr; };
    template<class T> friend class Tree;
};  

1 个答案:

答案 0 :(得分:0)

我在此处发布了TreeNode类的代码 - TonyD