回复 6楼 寒风中的细雨
程序代码:
#ifndef _BINNODE_H
#define _BINNODE_H
//Binary tree node abstract class
template <class Elem> class BinNode{
public:
//return the node's element
virtual Elem& val() = 0;
//set the node's element
virtual void setVal(const Elem &) = 0;
//return the node's left child
virtual BinNode* left() const = 0;
//set the node's left child
virtual void setLeft(BinNode*) = 0;
//return the node's right child
virtual BinNode* right() const = 0;
//set the node's right child
virtual void setRight(BinNode*) = 0;
//return true if the node is a leaf
virtual bool isLeaf() = 0;
};
#endif
#ifndef _BINNODEPTR_H
#define _BINNODEPTR_H
#include "BinNode.h"
// Binary tree node class
class KEComp{
public:
static bool lt(int x,int y){return x<y;}
static bool eq(int x,int y){return x==y;}
static bool gt(int x,int y){return x>y;}
};
template <class Elem>
class BinNodePtr : public BinNode<Elem> {
private:
Elem it; // The node's value
BinNodePtr* lc; // Pointer to left child
BinNodePtr* rc; // Pointer to right child
public:
BinNodePtr() { lc = rc = NULL; }
BinNodePtr(Elem e, BinNodePtr* l =NULL,
BinNodePtr* r =NULL)
{ it = e; lc = l; rc = r; }
Elem& val() { return it; }
void setVal(const Elem& e) { it = e; }
inline BinNode<Elem>* left() const
{ return lc; }
void setLeft(BinNode<Elem>* b)
{ lc = (BinNodePtr*)b; }
inline BinNode<Elem>* right() const
{ return rc; }
void setRight(BinNode<Elem>* b)
{ rc = (BinNodePtr*)b; }
bool isLeaf()
{ return (lc == NULL) && (rc == NULL); }
};
代码如上,请问那里出了问题?