Boost:编写自定义二叉树测试程序
在C++中,STL提供了各种标准容器和算法,但它们并不总是满足我们的需求。Boost库为开发者提供了许多高质量的扩展工具,使得我们能够轻松地实现自定义容器和算法。本文将演示如何使用Boost库来编写自定义的二叉树,并编写相应的测试程序。
首先,我们需要包含头文件和命名空间:
#include
#include <boost/container/binary_tree.hpp>
using namespace std;
using namespace boost::container;
接着,我们可以定义一个tree类来表示二叉树,并使用boost::container::binary_tree作为基础类:
template
class tree : public binary_tree<T, tree >
{
public:
typedef binary_tree<T, tree > base_type;
typedef typename base_type::allocator_type allocator_type;
explicit tree(const allocator_type& allocator = allocator_type())
: base_type(allocator) {}
template<typename InputIterator>
tree(InputIterator first, InputIterator last,