_rs_tree.c
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:2k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  _rs_tree.c
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #include <LEDA/impl/rs_tree.h>
  12. //----------------------------------------------------------------------------
  13. //  rs_tree:
  14. //
  15. //  rebalancing of randomized search trees
  16. //
  17. //----------------------------------------------------------------------------
  18. void rs_tree::insert_rebal(rs_tree_item v)
  19. {
  20.   rs_tree_item u = v->parent;
  21.   int prio = v->get_bal();
  22.   ROOT.set_bal(prio);
  23.   if (prio < u->get_bal())
  24.   {
  25.     int dir = (v == u->child[left]) ? left : right;
  26.     while (prio < u->get_bal())                /* rotate v up        */
  27.     {                                                /*       p            */
  28.       bin_tree_node* p = u->parent;                  /*       |            */
  29.       bin_tree_node* r = v->child[1-dir];            /*       |            */
  30.       u->child[dir] = r;                             /*       u            */
  31.       v->child[1-dir] = u;                           /*      /            */
  32.       u->parent = v;                                 /*     /             */
  33.       r->parent = u;                                 /*    *     v (prio)  */
  34.       propagate_modification(5,v,u);                 /*         /         */
  35.       propagate_modification(4,u,r);                 /*        /          */
  36.                                                      /*       r     *      */
  37.       dir = (u == p->child[left]) ? left : right;
  38.       u = p;
  39.      }
  40.   
  41.     // link to parent
  42.   
  43.     u->child[dir] = v;
  44.     v->parent = u;
  45.     if (u != &ROOT) 
  46.        propagate_modification(6,u,v);
  47.   }
  48. }
  49. void rs_tree::del_rebal(rs_tree_item, rs_tree_item) { }