【发布时间】:2018-10-11 05:49:14
【问题描述】:
我有一个使用模板的二叉搜索树类。所以我可以创建一个 Faculty 类型的 BST,但是有没有办法在 Faculty 类中包含一个 BST?
我想在 Faculty 类中保存一个整数树作为成员变量。
所以我会有一个 Faculty 树,并且每个节点(类型为 Faculty)都有自己的 Integer 树。
这是我尝试添加 BST 成员变量的 Faculty 类。从我在其他地方读到的内容来看,问题在于尝试#include BST.h 文件,因为我已经在 BST 文件中包含了 Faculty 文件。
#ifndef Faculty_H
#define Faculty_H
#include "Person.h"
#include "BST.h"
using namespace std;
class Faculty : public Person
{
public:
Faculty();
Faculty(int new_ID);
~Faculty();
friend ostream& operator<<(ostream& os, Faculty& f);
private:
BST<int> advisees;
};
#endif //Faculty_H
这是我的错误: ./Faculty.h:36:2:错误:未知类型名称“BST” BST 建议;
这是 BST.H
#ifndef BST_H
#define BST_H
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include "tree_node.h"
#include "tree_node.cpp"
#include "Person.h"
#include "Student.h"
#include "Faculty.h"
using namespace std;
template <class T>
class BST
{
public:
BST();
~BST();
void insert(T k);
tree_node<T>* find(T k);
bool contains(T k);
bool delete_node(T k);
tree_node<T> *get_min();
tree_node<T> *get_max();
tree_node<T> *get_root();
bool is_empty();
int get_size();
void print_tree(tree_node<T> *node);
tree_node<T>* get_successor(tree_node<T> *d);
private:
tree_node<T> *root;
unsigned int size;
};
#endif //BST_H
【问题讨论】:
-
BST.h的内容是什么? -
将在编辑中添加
标签: c++ search tree binary binary-search-tree