求助大神,使用vs2017建立二叉树时遇到了不允许使用不完整类型的问题,但是检查后没有发现问题,请问怎么解决?

以上是遇到的问题
以下是头文件中类的定义
#pragma once
#ifndef BST
#define BST
#include <iostream>
using namespace std;
//Binary tree node abstract class
template <typename E> class BinNode
{
public:
virtual ~BinNode(){}//Base destructor
//Return the node's value
virtual E& element() = 0;
//Set the node's value
virtual void setElement(const E&) = 0;
//Return the node's left child
virtual void BinNode*left()const = 0;
//Set the node's left child
virtual void setLeft(BinNode*) = 0;
//Return the node's right child
virtual void BinNode*right()const = 0;
//Set the node's right child
virtual void setRight(BinNode*) = 0;
//Return true if the node is a leaf,false otherwise
virtual bool isLeaf() = 0;
};
//Simple binary tree node implementation
template <typename Key,typename E>
class BSTnode :pubilc BinNode<E>
{
private:
Key k;//The node's key
E it;//The node's value
BSTnode* lc;//Pointer to left child
BSTnode* rc;//Pointer to right child
bool find(E e, BSTNode *root);
void insert(BSTNode<int, char> *node, BSTNode<int, char>** list, int& head, int tail);
public:
//Two constructors --with and without inital values
BSTnode() { lc = rc = NULL; }
BSTnode(Key k,E e,BSTnode*l=NULL,BSTnode*r=NULL)
{
k = K;
it = e;
lc = l;
rc = r;
}
~BSTnode(){}//Destructor
//Functions to set and return the vaulue and key
E& element() { return it; }
void setElement(const E& e) { it = e; }
Key& key() { return k; }
void setKey(const Key& K) { k = K; }
//Functions to set and return the children
inline BSTnode*left()const { return lc; }
void setLeft(BinNode<E>*b) { lc = (BSTnode*)b; }
inline BSTnode* right()const { return rc; }
void setRight(BinNode<E>*b) { rc = (BSTnode)*b; }
//Return true if it is a leaf,false otherwise
bool isLeaf() { return(lc == NULL) && (rc == NULL); }
//print
void print()
{
cout << element() << "\t";
}
//前序遍历
void preorder(BinNode<E>* root);
//中序遍历
void inorder(BinNode<E>* root);
//后序遍历
void postorder(BinNode<E>* root);
//利用前序、中序重建二叉树
BSTNode* reconstruction(E* pre, E* in, int i_1, int j_1, int i_2, int j_2);
int findRoot(E& pre_ele, E* in, int i_2, int j_2);
int tell(E* pre, E* in, int i_1, int j_1, int i_2, int j_2);
//建立二叉搜索树
BSTNode* buildBin(E* list, int len);
void locate(BSTNode* root, E e);
//二叉搜索
bool find(E e);
//huffman
BSTNode<int, char>* buildHuffman(BSTNode<int, char>** list, int len);
void print_huffman_code();
void pre(BSTNode<int, char> *root, char *code, int& pos);
};
template<typename Key, typename E>
inline bool BSTnode<Key, E>::find(E e, BSTNode * root)
{
if (root == 0) {
cout << "miss " << e << " in this tree" << endl;
return false;
}
if (e == root->element()) {
cout << "Find " << e << " in this bintree" << endl;
return true;
}
else if (e<root->element())
return find(e, root->left());
else
return find(e, root->right());
}
template<typename Key, typename E>
inline void BSTnode<Key, E>::insert(BSTNode<int, char>* node, BSTNode<int, char>** list, int & head, int tail)
{
int count = 0;
for (int i = head; i <= tail; i++) {
if (node->key() <= list[i]->key()) {
list[i - 1] = node;
if (i == head)
head--;
break;
}
else {
list[i - 1] = list[i];
list[i] = node;
count++;
}
}
if (count)
head--;
cout << "insert over" << endl;
for (int i = head; i <= tail; i++) {
//cout<<"--------"<<endl;
cout << list[i]->key() << "\t";
}
cout << endl;
}
//前序遍历
template<typename Key, typename E>
inline void BSTnode<Key, E>::preorder(BinNode<E>* root)
{
if (root == NULL)return;//Empty subtree, do nothing
//visit(root);//Perform desired action
root->print();
preorder(root->left());
preorder(root->right());
}
//中序遍历
template<typename Key, typename E>
inline void BSTnode<Key, E>::inorder(BinNode<E>* root)
{
if (root == NULL)return;//Empty subtree, do nothing
ineorder(root->left());
//visit(root);//Perform desired action
root->print();
ineorder(root->right());
}
//后序遍历
template<typename Key, typename E>
inline void BSTnode<Key, E>::postorder(BinNode<E>* root)
{
if (root == NULL)return;//Empty subtree, do nothing
postorder(root->left());
postorder(root->right());
//visit(root);//Perform desired action
root->print();
}
//利用前序、中序重建二叉树
template<typename Key, typename E>
inline BSTNode * BSTnode<Key, E>::reconstruction(E * pre, E * in, int i_1, int j_1, int i_2, int j_2)
{
this->setElement(pre[i_1]);
if (j_1 - i_1 != j_2 - i_2)
{
cout << "reconstruct error!!!" << endl;
return 0;
}
if (i_1 == j_1 && i_2 == j_2)
return 0;
int root = findRoot(pre[i_1], in, i_2, j_2);
cout << "root----- " << root << endl;
if (root<0) return 0;
int rc = tell(pre, in, i_1 + 1, j_1, i_2, root - 1);
cout << "rc----- " << rc << endl;
//if(rc<0) return 0;
if (rc>0)
{
this->setLeft(new BSTNode(0, pre[i_1 + 1]));
this->setRight(new BSTNode(1, pre[rc]));
}
else
{
this->setRight(new BSTNode(1, pre[i_1]));
}
if (this->left())
this->left()->reconstruction(pre, in, i_1 + 1, rc - 1, i_2, root - 1);
this->right()->reconstruction(pre, in, rc, j_1, root + 1, j_2);
return this;
}
template<typename Key, typename E>
inline int BSTnode<Key, E>::findRoot(E & pre_ele, E * in, int i_2, int j_2)
{
for (int i = i_2; i <= j_2; i++) {
if (in[i] == pre_ele)
return i;
}
cout << endl << "can not find root " << pre_ele << endl;
return -1;
}
template<typename Key, typename E>
inline int BSTnode<Key, E>::tell(E * pre, E * in, int i_1, int j_1, int i_2, int j_2)
{
for (int v = j_2; v >= i_2; v--) {
for (int t = i_1; t <= j_1; t++) {
if (pre[t] == in[v] && t - i_1 == j_2 - i_2)
return t + 1;
}
}
cout << "print the miss ls" << endl;
for (int i = i_2; i <= j_2; i++)
cout << in[i] << "\t";
cout << "can not tell" << endl;
return -1;
}
//建立二叉搜索树
template<typename Key, typename E>
inline BSTNode * BSTnode<Key, E>::buildBin(E * list, int len)
{
setElement(list[0]);
for (int i = 1; i<len; i++) {
locate(this, list[i]);
}
return this;
}
template<typename Key, typename E>
inline void BSTnode<Key, E>::locate(BSTNode * root, E e)
{
if (e <= root->element()) {
if (root->left() == 0)
root->setLeft(new BSTNode(0, e));
else
locate(root->left(), e);
}
else {
if (root->right() == 0)
root->setRight(new BSTNode(1, e));
else
locate(root->right(), e);
}
}
//二叉搜索
template<typename Key, typename E>
inline bool BSTnode<Key, E>::find(E e)
{
cout << "Find " << e << " in this bintree" << endl;
return true;
}
//huffman
template<typename Key, typename E>
inline BSTNode<int, char>* BSTnode<Key, E>::buildHuffman(BSTNode<int, char>** list, int len)
{
int head = 0;
int tail = len - 1;
BSTNode<int, char> *temp1, *temp2, *temp3;
temp1 = temp2 = temp3 = 0;
while (head<tail) {///////
temp1 = list[head];
temp2 = list[head + 1];
//delete list[head];
//delete list[head+1];
head += 2;
temp3 = new BSTNode<int, char>(temp1->key() + temp2->key(), 0, temp1, temp2);
//cout<<head<<endl;
insert(temp3, list, head, tail);
//delete temp1;
//delete temp2;
}
cout << "build huffman over" << endl;
//temp3->print_Preorder();
return temp3;
}
template<typename Key, typename E>
inline void BSTnode<Key, E>::print_huffman_code()
{
cout << "begin code======" << endl;
char code[50];
//cout<<"begin code"<<endl;
int pos = 0;
pre(this, code, pos);
//delete code;
}
template<typename Key, typename E>
inline void BSTnode<Key, E>::pre(BSTNode<int, char>* root, char * code, int & pos)
{
if (root->element()) {
cout << root->element() << " : " << code << endl;
code[--pos] = '\0';
//pos--;
return;
}
code[pos] = '0';
code[++pos] = '\0';
pre(root->left(), code, pos);
code[pos] = '1';
code[++pos] = '\0';
pre(root->right(), code, pos);
code[--pos] = '\0';
};
#endif
...全文


新手乐园
