#ifndef BINARYTREE_H
#define BINARYTREE_H
template<typename T>
class TreeNode
{
public:
T element; // Element contained in the node
TreeNode<T> * left; // Pointer to the left child
TreeNode<T> * right; // Pointer to the right child
TreeNode() // No-arg constructor
{
previous = NULL;
next = NULL;
}
TreeNode(T element) // Constructor
{
this->element = element;
left = NULL;
right = NULL;
}
};
template < typename T >
class BinaryTree
{
public:
BinaryTree();
BinaryTree(T elements[]);
bool insert(T element);
void inorder();
void preorder();
void postorder();
int getSize();
private:
TreeNode<T> * root;
int size;
void inorder(TreeNode<T> *root);
void postorder(TreeNode<T> *root);
void preorder(TreeNode<T> *root);
};
template < typename T >
BinaryTree<T>::BinaryTree()
{
root = NULL;
size = 0;
}
/* Inse
二叉树 BinaryTree.h
最新推荐文章于 2022-11-30 23:13:28 发布