Guest User

AVL Tree Rotation

a guest
Aug 2nd, 2011
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. bool avl_search_tree::avl_tree_node::rotate_left()
  2. {
  3.     if (_right_child != NULL) {
  4.         avl_tree_node *new_root = _right_child;
  5.  
  6.         if (_parent != NULL) {
  7.             if (_parent->_left_child == this) {
  8.                 _parent->_left_child = new_root;
  9.             } else {
  10.                 _parent->_right_child = new_root;
  11.             }
  12.         }
  13.  
  14.         new_root->_parent = _parent;
  15.         _parent = new_root;
  16.  
  17.         _right_child = new_root->_left_child;
  18.         new_root->_left_child = this;
  19.  
  20.         if (_right_child != NULL) {
  21.             _right_child->_parent = this;
  22.         }
  23.  
  24.         //update heights
  25.         update_height();
  26.         new_root->update_height();
  27.  
  28.         return true;
  29.     }
  30.  
  31.     return false;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment