Kylin/DataStructure/Tree.h

37 lines
807 B
C
Raw Normal View History

2023-12-27 10:29:16 +08:00
#ifndef TREE_H
#define TREE_H
#include "Object.h"
namespace Kylin {
template <typename T>
class TreeNode {
public:
TreeNode(const T &value, TreeNode<T> *parent) : value(value), parent(parent) {}
T value;
TreeNode<T> *parent = nullptr;
virtual ~TreeNode() {}
};
template <typename T>
class Tree : public Object {
public:
virtual bool insert(TreeNode<T> *node) = 0;
virtual TreeNode<T> *find(const T &value) const = 0;
virtual bool find(TreeNode<T> *node) const = 0;
virtual TreeNode<T> *root() const = 0;
virtual int degree() const = 0;
virtual int count() const = 0;
virtual int height() const = 0;
virtual void clear() = 0;
protected:
TreeNode<T> *m_root = nullptr;
};
} // namespace Kylin
#endif // TREE_H