不好意思,一开始看错了。
这是queue里的声明:
virtual void enQueue(const char &x) = 0;
这是linkQueue里的:
void enQueue(const char x) ;
看出不同没?一个参数是引用类型,一个是传值。改成一样就可以了。
补充:
tmp是Node*类型,但是deQueue()返回的是char类型,两种类型不匹配,所以出错了。
#ifndef _binarytree_h
#define _binarytree_h
#include
class queue
{ public:
virtual bool isEmpty() = 0;
virtual void enQueue(const char &x) = 0;
virtual char deQueue() = 0;
virtual char getHead() = 0;
virtual ~queue() {}
};
class linkQueue: public queue
{ private:
struct node {
char data;
node *next;
node(const char &x, node *N = NULL)
{ data = x; next = N;}
node():next(NULL) {}
~node() {}
};
node *front, *rear;
public:
linkQueue() { front = rear = NULL; }
~linkQueue();
bool isEmpty() {return front == NULL;}
void enQueue(const char x) ; //少& -->const char &x
char deQueue() ;
char getHead() {return front->data;}
};
linkQueue::~linkQueue() {
node *tmp;
while (front != NULL) {
tmp = front;
front = front->next;
delete tmp;
}
}
void linkQueue::enQueue(const char x) //少& (const char &x)
{ if (rear == NULL)
front = rear = new node(x);
else {
rear->next = new node(x);
rear = rear->next;
}
}
char linkQueue::deQueue() {
node *tmp = front;
char value = front->data;
front = front->next;
if (front == NULL) rear = NULL;
delete tmp;
return value;
}
class BinaryTree {
……
……
void createTree(char flag)
{ linkQueue que;
Node *tmp;
char x, ldata, rdata;
cout << "\nêäèë¸ù½áμã£o";
cin >> x;
root = new Node(x);
que.enQueue(root->data);
while (!que.isEmpty()) {
tmp = que.deQueue();
cout << "\nêäèë" << tmp->data
<< "μÄὸö¶ù×ó(" << flag
<< "±í꾿սáμã)£o";
cin >> ldata >> rdata;
if (ldata != flag)
que.enQueue(tmp->left = new Node(ldata));
if (rdata != flag)
que.enQueue(tmp->right = new Node(rdata));
}
cout << "create completed!\n";
}
#endif