home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ledar34.zip / leda-r-3_4_tar / LEDA-3.4 / src / dict / _rs_tree.c < prev    next >
C/C++ Source or Header  |  1996-09-03  |  2KB  |  69 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA 3.4
  4. +
  5. +  _rs_tree.c
  6. +
  7. +  This file is part of the LEDA research version (LEDA-R) that can be 
  8. +  used free of charge in academic research and teaching. Any commercial
  9. +  use of this software requires a license which is distributed by the
  10. +  LEDA Software GmbH, Postfach 151101, 66041 Saarbruecken, FRG
  11. +  (fax +49 681 31104).
  12. +
  13. +  Copyright (c) 1991-1996  by  Max-Planck-Institut fuer Informatik
  14. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  15. +  All rights reserved.
  16. *******************************************************************************/
  17. #include <LEDA/impl/rs_tree.h>
  18.  
  19. //----------------------------------------------------------------------------
  20. //  rs_tree:
  21. //
  22. //  rebalancing of randomized search trees
  23. //
  24. //  S. N"aher (1993)
  25. //----------------------------------------------------------------------------
  26.  
  27.  
  28. void rs_tree::insert_rebal(rs_tree_item v)
  29. {
  30.   rs_tree_item u = v->parent;
  31.  
  32.   int prio = v->get_bal();
  33.  
  34.   ROOT.set_bal(prio);
  35.  
  36.   if (prio < u->get_bal())
  37.   {
  38.     int dir = (v == u->child[left]) ? left : right;
  39.  
  40.     while (prio < u->get_bal())                   /* rotate v up        */
  41.     {                                                /*       p            */
  42.       bin_tree_node* p = u->parent;                  /*       |            */
  43.       bin_tree_node* r = v->child[1-dir];            /*       |            */
  44.       u->child[dir] = r;                             /*       u            */
  45.       v->child[1-dir] = u;                           /*      / \           */
  46.       u->parent = v;                                 /*     /   \          */
  47.       r->parent = u;                                 /*    *     v (prio)  */
  48.       propagate_modification(5,v,u);                 /*         / \        */
  49.       propagate_modification(4,u,r);                 /*        /   \       */
  50.                                                      /*       r     *      */
  51.       dir = (u == p->child[left]) ? left : right;
  52.       u = p;
  53.      }
  54.   
  55.     // link to parent
  56.   
  57.     u->child[dir] = v;
  58.     v->parent = u;
  59.  
  60.     if (u != &ROOT) 
  61.        propagate_modification(6,u,v);
  62.   }
  63.  
  64. }
  65.  
  66. void rs_tree::del_rebal(rs_tree_item, rs_tree_item) { }
  67.  
  68.