csdn博客又疯了..

今天怎么老是又发不出文章出去..一发就错误..我真是服了它了

展开阅读全文

啊。。。。疯了。。关于模板类。。。又出错又出错

05-07

这是头文件..rn[code=C/C++]#ifndef BINARYSEARCHTREE_Hrnrn#define BINARYSEARCHTREE_Hrnrntemplaternclass BinarySearchTreernrn public:rn BinarySearchTree();rn ~BinarySearchTree();rn BinarySearchTree( const BinarySearchTree &rhs );rn BinarySearchTree &operator=( const BinarySearchTree &rhs );rnrn /**rn * 查找这棵树的最大值rn * 返回该最大值rn */rn const Object &FindMax() const;rnrn /** rn * 用于查找这棵树的最小值rn * 返回该最小值rn */rn const Object &FindMin() const;rnrn /**rn * 用于查询一个值是否在树里rn * element是需要查找的值rn * 如果element在这棵树里,返回true,否则为falsern */rn bool Contains( const Object &element ) const;rnrn /**rn * 用于判断一棵树是否为空rn * 如果该树为空树,返回true,否则返回falsern */rn bool Empty() const;rnrn /**rn * 用于打印一棵树,前序rn */rn void PrintfTree() const;rnrn /**rn * 删除一棵树所有节点,使之为空。rn */rn void MakeEmpty();rnrn /**rn * 在一棵子树上插入一个节点。rn * element为需要插入的数据rn * 插入一个新节点rn */rn void Insert( const Object &element );rnrn /**rn * 在一棵子树上删除一个节点rn * element为需要删除的节点rn */rn void Remove( const Object &element );rnrnrn private:rnrn struct Nodern rn Node( const Object &element, Node *left, Node *right ):rn m_element(element), m_left(left), rn m_right(right)rn rn rnrn Object m_element;rn Node *m_left;rn Node *m_right;rn ;rnrn Node *root;rnrn void Insert( const Object &element, Node *&tree ) const;rn void Remove( const Object &element, Node *&tree ) const;rn bool Contians( const Object &element, Node *&tree ) const;rn void MakeEmpty( Node *&tree );rn void PrintTree( Node *tree ) const;rn Node *Clone( Node *tree ) const;rn Node *FindMax( Node *tree ) const;rn Node *FindMin( Node *tree ) const;rn;rnrn#endifrn[/code]rnrnrn这是源文件,只求编译通过rnrn[code=C/C++]#include "BinarySearchTree.h"rn#include rnrntemplaternBinarySearchTree::BinarySearchTree( const BinarySearchTree &rhs )rnrn this->operator=(rhs);rnrnrntemplaternBinarySearchTree &BinarySearchTree::operator=( const BinarySearchTree &rhs )rnrn if( this != &rhs )rn rn MakeEmpty();rn root = Clone( rhs.root );rn rnrn return *this;rnrnrntemplaternvoid BinarySearchTree::MakeEmpty()rnrn MakeEmpty( root );rnrnrntemplaternvoid BinarySearchTree::MakeEmpty( Node *&tree )rnrn if( tree == NULL )rn rn return;rn rnrn if( tree->m_left != NULL )rn rn MakeEmpty( tree->m_left );rn rnrn if( tree->m_right != NULL )rn rn MakeEmpty( tree->m_right );rn rn rn delete tree;rnrnrntemplaternBinarySearchTree::Node *Clone( Node *tree ) constrnrn if( tree == NULL )rn rn return NULL;rn rn elsern rn return new Node( tree->m_element, Clone(tree->m_left),rn Clone(tree->m_right) );rn rnrnrntemplaternBinarySearchTree::~BinarySearchTree()rnrn MakeEmpty();rnrn[/code]rnrn 论坛

没有更多推荐了,返回首页