background image

c++

   实现二叉搜索树

 

 

[C/C++]

    

代码

#ifndef SEARCHBINARYTREE_CPP_

#define SEARCHBINARYTREE_CPP_

#include<iostream>

using namespace std;

template <typename Comparable>

class BinarySearchTree

{

    public:

        BinarySearchTree();

        BinarySearchTree( const BinarySearchTree & rhs);

        ~BinarySearchTree();

        const Comparable & findMin() const;

        const Comparable & findMax() const;

        bool contains( const Comparable & x) const;

        bool isEmpty() const;

        void printTree(ostream &) const;

        void makeEmpty();

        void insert( const Comparable & x);

        void remove( const Comparable & x);

        const BinarySearchTree & operator=(const BinarySearchTree & rhs);

        typedef struct BinaryNode

        {

            Comparable element;

            BinaryNode *left;