【发布时间】:2014-08-01 06:17:03
【问题描述】:
我不确定我是否应该.. 或不应该使用结构来创建二叉搜索树,另一种选择是从单独的节点类中创建节点。带有数据,左右。哪一个更好?为什么?
这是我的 BST 代码
template <typename T>
class BST : public SearchableADT<T>
{
public:
BST(void){ head = NULL; numnodes = 0; }
virtual ~BST(void);
virtual int loadFromFile(string filename);
virtual void clear(void);
virtual void insertEntry(T info);
virtual void deleteEntry(T info);
virtual bool isThere(T info);
virtual int numEntries(void);
//needed for comparison to AVL
int BST<T>::height(t_node* tPTR);
protected:
struct t_node
{
string data;
t_node *L;
t_node *R;
};
int numnodes;
t_node* head;
t_node* cPTR; //current pointer
t_node* pPTR; //parent pointer
t_node* tPTR; //temporary pointer
}; // end of class BST
【问题讨论】:
-
标准库已经支持
std::set和std::map形式的二叉树,你可以随时在算法库(lower_bound/@987654325)中使用带有二叉搜索功能的另一个容器@/binary_search). -
谢谢,但我只是想知道使用该结构是否可以。如果不是,为什么类 Node 会更好
标签: c++ visual-studio-2012 binary-search-tree