Page 154 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 154

Unit 6: Binary Search Tree and AVL Trees





              void insert( const Comparable & x )                                               Notes
              {
                  insert( x, root );
              }

              /**
               * Remove x from the tree. Nothing is done if x is not found.
               */
              void remove( const Comparable & x )
              {
                  cout << “Sorry, remove unimplemented; “ << x <<
                          “ still present” << endl;
              }


              /**
               * Deep copy.
               */
              const AvlTree & operator=( const AvlTree & rhs )
              {
                  if( this != &rhs )
                  {
                      makeEmpty( );
                      root = clone( rhs.root );
                  }
                  return *this;
              }


            private:
              struct AvlNode
              {
                  Comparable element;
                  AvlNode   *left;
                  AvlNode   *right;
                  int       height;


                  AvlNode( const Comparable & theElement, AvlNode *lt,
                                                          AvlNode *rt, int h = 0 )
                    : element( theElement ), left( lt ), right( rt ), height( h ) { }
              };






                                           LOVELY PROFESSIONAL UNIVERSITY                                   149
   149   150   151   152   153   154   155   156   157   158   159