????????????????
????????????У????????????????????????????????????????????????????У?????????????е???塣?????????????????????????????е??????????????????????? ??????????????????????????????????????
???????????е???????X?????????????????????????С??X?е???
???????????е???????Y?????????????????????????????X?е??
??????????????????????
?????????????????????????????????????????????????????????????
????template<class T>
????class BinarySearchTree
????{
????public:
????// ?????????????root?
????BinarySearchTree() : root(NULL){}
????// ????????????????
????~BinarySearchTree() {}
????// ????С?????????С?
????const T &findMin() const;
????// ????????????????
????const T &findMax() const;
????// ?ж???????????????????????
????bool contains(const T &x) const;
????// ?ж???????????????
????bool isEmpty() const { return root ? false : true; }
????// ???????????????
????void printTree() const;
????// ???????????в???????
????void insert(const T &x);
????// ????????????????????
????void remove(const T &x);
????// ????????????????
????void makeEmpty() const;
????private:
????// ???????
????BinaryNode<T> *root;
????void insert(const T &x?? BinaryNode<T> *&t) const;
????void remove(const T &x?? BinaryNode<T> *&t) const;
????BinaryNode<T> *findMin(BinaryNode<T> *t) const;
????BinaryNode<T> *findMax(BinaryNode<T> *t) const;
????bool contains(const T &x?? BinaryNode<T> *t) const;
????void printTree(BinaryNode<T> *t) const;
????void makeEmpty(BinaryNode<T> *&t) const;
????};
????findMin??findMax???
???????????????????????
???????????е???????X?????????????????????????С??X?е???
???????????е???????Y?????????????????????????????X?е??
????????????root??????
???????????????????????????????NULL???????????????С????
???????????????????????????????NULL?????????????????????
??????????????

????????????????????????????
?????????????
??????÷??????????
????????finMin??????????????????????????ο????£?
????BinaryNode<T> *BinarySearchTree<T>::findMin(BinaryNode<T> *t) const
????{
????if (t == NULL)
????{
????return NULL;
????}
????else if (t->left == NULL)
????{
????return t;
????}
????else
????{
????return findMin(t->left);
????}
????}
??????findMin()?????????findMin(BinaryNode<T> *t)????????????????????root???????????????????????????????С??????????????????????findMax??
????template<class T>
????BinaryNode<T> *BinarySearchTree<T>::findMax(BinaryNode<T> *t) const
????{
????if (t == NULL)
????{
????return NULL;
????}
????while (t->right)
????{
????t = t->right;
????}
????return t;
????}
?????????????????£?????????????д???????汾????????????е?????????????????????????????????????????????????汾??????£??????????????????汾??
????contains???
????contains?????ж??????????????????????????????????£?
????template<class T>
????bool BinarySearchTree<T>::contains(const T &x?? BinaryNode<T> *t) const
????{
????if (t == NULL)
????{
????return false;
????}
????else if (x > t->element)
????{
????return contains(x?? t->right);
????}
????else if (x < t->element)
????{
????return contains(x?? t->left);
????}
????else
????{
????return true;
????}
????}
?????????????£?
?????????ж????????????????????С?????
??????С??????????????????м????????
??????????????????????????м????????
?????????????????????true??
????insert???
????insert???????????????????в????μ??????????????£?
?????????ж????????????????????С?????
??????С??????????????????м???????????
??????????????????????????м???????????
?????????????????????????ɡ?
??????????????£?
????template<class T>
????void BinarySearchTree<T>::insert(const T &x?? BinaryNode<T> *&t) const
????{
????if (t == NULL)
????{
????t = new BinaryNode<T>(x?? NULL?? NULL);
????}
????else if (x < t->element)
????{
????insert(x?? t->left);
????}
????else if (x > t->element)
????{
????insert(x?? t->right);
????}
????}
????remove???
????remove????????????????????????????????????????????????鷳????????????????????????????????п????????????????????? ??????????

??????????????????????κ???????????е???9?????17?????21?????56????88????Щ???????????????
??????????????????????????????????????????????????е???16????40????Щ??????????????????
???????????????????????????????????е???66???
???????????1?????????????????????????????????
???????????2???????????????????????????????????λ???
???????????3????????????????????????????????????????С???????????С??滻???????????????????????????????С????