• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ right_rotate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中right_rotate函数的典型用法代码示例。如果您正苦于以下问题:C++ right_rotate函数的具体用法?C++ right_rotate怎么用?C++ right_rotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了right_rotate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: height

struct node *balance(struct node *t )
{ unsigned int tmp ;
  unsigned int tmp___0 ;
  unsigned int tmp___1 ;
  unsigned int tmp___2 ;
  unsigned int tmp___3 ;
  unsigned int tmp___4 ;
  unsigned int tmp___5 ;
  unsigned int tmp___6 ;

  {
  tmp___5 = height(t->left);
  tmp___6 = height(t->right);
  if (tmp___5 > 1U + tmp___6) {
    tmp = height((t->left)->left);
    tmp___0 = height((t->left)->right);
    if (tmp < tmp___0) {
      t->left = left_rotate(t->left);
    }
    t = right_rotate(t);
  } else {
    tmp___3 = height(t->left);
    tmp___4 = height(t->right);
    if (tmp___3 + 1U < tmp___4) {
      tmp___1 = height((t->right)->left);
      tmp___2 = height((t->right)->right);
      if (tmp___1 > tmp___2) {
        t->right = right_rotate(t->right);
      }
      t = left_rotate(t);
    }
  }
  return (t);
}
}
开发者ID:JasonGross,项目名称:c-semantics,代码行数:35,代码来源:avl_tree.cil.c


示例2: maintain

int maintain(int &t,int flag)
{
	if (flag==0)//
	{
		if (SBT[SBT[SBT[t].left].left].s>SBT[SBT[t].right].s)
			right_rotate(t);
		else if (SBT[SBT[SBT[t].left].right].s>SBT[SBT[t].right].s)
		{
			left_rotate(SBT[t].left);
			right_rotate(t);
		}
		else return t;
	}
	else
	{
		if (SBT[SBT[SBT[t].right].right].s>SBT[SBT[t].left].s)
			left_rotate(t);
		else if (SBT[SBT[SBT[t].right].left].s>SBT[SBT[t].left].s)
		{
			right_rotate(SBT[t].right);
			left_rotate(t);
		}
		else return t;
	}
	maintain(SBT[t].left,0);
	maintain(SBT[t].right,1);
	maintain(t,0);
	maintain(t,1);
	return t;
}
开发者ID:comzyh,项目名称:ICPCcode,代码行数:30,代码来源:1442.cpp


示例3: btree_delete_fixup

/* Fixup the balance of the btree after deletion    */
static void btree_delete_fixup(opal_rb_tree_t *tree, opal_rb_tree_node_t * x)
{
    opal_rb_tree_node_t * w;
    opal_rb_tree_node_t * root = tree->root_ptr->left;
    while ((x != root) && (x->color == BLACK)) {
        if (x == x->parent->left) {
            w = x->parent->right;
            if (w->color == RED) {
                w->color = BLACK;
                x->parent->color = RED;
                left_rotate(tree, x->parent);
                w = x->parent->right;
            }
            if ((w->left->color == BLACK) && (w->right->color == BLACK)) {
                w->color = RED;
                x = x->parent;
            } else {
                if (w->right->color == BLACK) {
                    w->left->color = BLACK;
                    w->color = RED;
                    right_rotate(tree, w);
                    w = x->parent->right;
                }
                w->color = x->parent->color;
                x->parent->color = BLACK;
                w->right->color = BLACK;
                left_rotate(tree, x->parent);
                x = root;
            }
        } else { /* right    */

            w = x->parent->left;
            if (w->color == RED) {
                w->color = BLACK;
                x->parent->color = RED;
                right_rotate(tree, x->parent);
                w = x->parent->left;
            }
            if ((w->right->color == BLACK) && (w->left->color == BLACK)) {
                w->color = RED;
                x = x->parent;
            } else {
                if (w->left->color == BLACK) {
                    w->right->color = BLACK;
                    w->color = RED;
                    left_rotate(tree, w);
                    w = x->parent->left;
                }
                w->color = x->parent->color;
                x->parent->color = BLACK;
                w->left->color = BLACK;
                right_rotate(tree, x->parent);
                x = root;
            }
        }
    }

    x->color = BLACK;
    return;
}
开发者ID:Greatrandom,项目名称:ompi,代码行数:61,代码来源:opal_rb_tree.c


示例4: while

void RBTree::remove_fixup(rbnode * x)
{
    while (x != root && x->color == BLACK) {
        rbnode * p = x->parent;
        if (x == p->lc) { // LEFT CHILD
            rbnode * w = p->rc;
            if (w->color == RED) {
                p->color = RED;
                w->color = BLACK;
                left_rotate(p);
                w = p->rc;
            }

            if (w->lc->color == BLACK && w->rc->color == BLACK) {
                w->color = RED;
                x = p;
            } else {
                if (w->rc->color == BLACK) { // w->rc is red
                    w->color = RED;
                    w->lc->color = BLACK;
                    w = right_rotate(w);
                }

                w->color = p->color;
                p->color = BLACK;
                w->rc->color = BLACK;
                left_rotate(p);

                x = root;
            }
        } else { // right child
            rbnode * w = p->lc;
            if (w->color == RED) {
                p->color = RED;
                w->color = BLACK;
                right_rotate(p);
                w = p->lc;
            }

            if (w->lc->color == BLACK && w->rc->color == BLACK) {
                w->color = RED;
                x = p;
            } else {
                if (w->lc->color == BLACK) { // w->rc is red
                    w->color = RED;
                    w->rc->color = BLACK;
                    w = left_rotate(w);
                }

                w->color = p->color;
                p->color = BLACK;
                w->lc->color = BLACK;
                right_rotate(p);

                x = root;
            }
        }
    }
    x->color = BLACK;
}
开发者ID:venux021,项目名称:mustard,代码行数:60,代码来源:rbtree.sample.cpp


示例5: while

void rb_tree<T>::remove_fixup(rb_vertex<T>* current_vertex) {
    // current_vertex is x in Corman

    // this is w in Corman
    rb_vertex<T>* child;

    while (current_vertex != root && current_vertex->get_colour() == BLACK) {
        if (current_vertex == current_vertex->get_parent()->get_left_child()) {
            child = current_vertex->get_parent()->get_right_child();
            if (child->get_colour() == RED) {
                child.set_colour(BLACK);
                current_vertex->get_parent()->set_colour(RED);
                left_rotate(current_vertex->get_parent);
                child = current_vertex->get_parent->get_right_child();
            }
            if (child->get_left_child()->get_colour() == BLACK && child->get_right_child()->get_colour() == BLACK) {
                child->set_colour(RED);
                current_vertex = current_vertex->get_parent();
            } else {
                if (child->get_right_child()->get_colour() == BLACK) {
                    child->get_left_child()->set_colour(BLACK);
                    child->set_colour(RED);
                    right_rotate(child);
                    child = current_vertex->get_parent()->get_right_child();
                }
                child->set_colour(current_vertex->get_parent()->get_colour());
                current_vertex->get_parent()->set_colour(BLACK);
                child->get_right_child()->set_colour(BLACK);
                left_rotate(current_vertex->get_parent());
                current_vertex = root;
            }
        } else {
            child = current_vertex->get_parent()->get_left_child();
            if (child->get_colour() == RED) {
                child.set_colour(BLACK);
                current_vertex->get_parent()->set_colour(RED);
                right_rotate(current_vertex->get_parent);
                child = current_vertex->get_parent->get_left_child();
            }
            if (child->get_left_child()->get_colour() == BLACK && child->get_right_child()->get_colour() == BLACK) {
                child->set_colour(RED);
                current_vertex = current_vertex->get_parent();
            } else {
                if (child->get_left_child()->get_colour() == BLACK) {
                    child->get_right_child()->set_colour(BLACK);
                    child->set_colour(RED);
                    left_rotate(child);
                    child = current_vertex->get_parent()->get_left_child();
                }
                child->set_colour(current_vertex->get_parent()->get_colour());
                current_vertex->get_parent()->set_colour(BLACK);
                child->get_left_child()->set_colour(BLACK);
                right_rotate(current_vertex->get_parent());
                current_vertex = root;
            }
        }
    }

    current_vertex->set_colour(BLACK);
}
开发者ID:kjmikkel,项目名称:rb_tree,代码行数:60,代码来源:rb_tree.cpp


示例6: rb_delete_fixup

static void rb_delete_fixup(tree_p tr, tnode_p parent, tnode_p node){
	tnode_p sibling;
	while(node != tr->root && rb_color(node) == BLACK){
		if( node == parent->left ){
			sibling = parent->right;
			if(rb_color(sibling) == RED){
				sibling->color = BLACK;
				parent->color = RED;
				left_rotate(tr, parent);
				sibling = parent->right;
			}

			if(rb_color(sibling->left) == BLACK 
					&& rb_color(sibling->right) == BLACK){
				sibling->color = RED;
				node = parent;
				parent = parent->parent;
			} else if(rb_color(sibling->right) == BLACK){
				sibling->left->color = RED;
				right_rotate(tr, sibling);
				sibling = parent->right;
			} else {
				sibling->color = parent->color;
				parent->color = BLACK;
				sibling->right->color = BLACK;
				left_rotate(tr, parent);
				node = tr->root;
				parent = NULL;
			}
		}
		else{
			sibling = parent->left;
			if(rb_color(sibling) == RED){
				sibling->color = BLACK;
				parent->color = RED;
				right_rotate(tr, parent);
				sibling = parent->left;
			}

			if(rb_color(sibling->left) == BLACK 
					&& rb_color(sibling->right) == BLACK){
				sibling->color = RED;
				node = parent;
				parent = parent->parent;
			} else if(rb_color(sibling->left) == BLACK){
				sibling->right->color = RED;
				left_rotate(tr, sibling);
				sibling = parent->left;
			} else {
				sibling->color = parent->color;
				parent->color = BLACK;
				sibling->left->color = BLACK;
				right_rotate(tr, parent);
				node = tr->root;
				parent = NULL;
			}
		}
	}
	if(node != NULL) node->color = BLACK;
}
开发者ID:Limaa,项目名称:libds,代码行数:60,代码来源:tree.c


示例7: rebalance_AVL

/* rebalance_AVL: checks if the left and right branches of the tree are even,
* if they are not. Check which rotation needs to be carried out and do it.
*
* Params: the AVL root node, and last value entered.
*
* Returns: a newly balanced tree if rebalancing is needed, or just returns
* the current root if no balancing is necessary.
*/
static AVL rebalance_AVL(AVL self, int value)
{
	int balance;

	/* update the height of the ancestor */
	self->height = maximum(height(self->left), height(self->right)) + 1;

	/* check that the left and right subtrees are balanced. */
	balance = check_balance(self);

	/* check for left rotate */
	if (balance > 1 && value < self->student_id) {
		return right_rotate(self);
	}
	/* check for right rotate */
	if (balance < -1 && value > self->student_id) {
		return left_rotate(self);
	}
	/* check for double rotate (left then right) */
	if (balance > 1 && value > self->left->student_id) {
		self->left = left_rotate(self);
		return right_rotate(self);
	}
	/* check for double rotate (right then left) */
	if (balance < -1 && value < self->right->student_id) {
		self->right = right_rotate(self);
		return left_rotate(self);
	}
	return self;
}
开发者ID:daniel-k-richardson,项目名称:Assignments-for-KIT205,代码行数:38,代码来源:avl.c


示例8: tree_fix

/**
 * Balances red black trees.
 * @param t tree to balance.
 * @return balanced tree.
 */
static tree tree_fix(tree t)
{
  if(IS_RED(t->left) && IS_RED(t->left->left)){
    if(IS_RED(t->right)){
      /*colour root red and children a,b black*/
      t->colour = RED;
      t->left->colour = BLACK;
      t->right->colour = BLACK;
    }else if(IS_BLACK(t->right)){
      /*right rotate root , colour new root (a) black,
       * and new child(old root) red*/
      t = right_rotate(t);
      t->colour = BLACK;
      t->right->colour = RED;/*old root*/
    }
  }else if(IS_RED(t->left) && IS_RED(t->left->right)){
    if(IS_RED(t->right)){
      /*colour root red and children a,b black*/
      t->colour = RED;
      t->left->colour = BLACK;
      t->right->colour = BLACK;
    }
    else if(IS_BLACK(t->right)){
      /* Left rotate left child (a), right rotate root (r),
       * colour new root (d) black and new child (R) red */
      t->left = left_rotate(t->left);
      t = right_rotate(t);
      t->colour = BLACK;
      t->right->colour = RED;/* old root */
    }
  }else if(IS_RED(t->right) && IS_RED(t->right->left)){
    if(IS_RED(t->left)){
      /* Colour root (R) red and children (a,b) black*/
      t->colour = RED;
      t->left->colour = BLACK;
      t->right->colour = BLACK;
    }else if(IS_BLACK(t->left)){
      /* Right rotate right child(b),left rotate root(r),
       * colour new root (e) black and new child (r) red */
      t->right = right_rotate(t->right);
      t = left_rotate(t);
      t->colour = BLACK;
      t->left->colour = RED;/* old root */
    }
  }else if(IS_RED(t->right) && IS_RED(t->right->right)){
    if(IS_RED(t->left)){
      /* Colour root (R) red and children (A,B) black */
      t->colour = RED;
      t->left->colour = BLACK;
      t->right->colour = BLACK;
    }
    else if(IS_BLACK(t->left)){
      /* Left rotate root R, colour new root b black and new child R red */
      t = left_rotate(t);
      t->colour = BLACK;
      t->left->colour = RED;/*old root*/
    }
  }
  return t;
}
开发者ID:lchish,项目名称:cosc,代码行数:65,代码来源:tree.c


示例9: rb_delete_fixup

void
rb_delete_fixup(RB_TREE *T, RB_NODE *x)
{
    RB_NODE     *w;

    while (x != T->root && x->color == BLACK) {
        if (x == x->parent->left) {
            w = x->parent->right;
            if (w->color == RED) {
                w->color = BLACK;                               //case 1
                x->parent->color = RED;                         //case 1
                left_rotate(T, x->parent);                      //case 1
                w = x->parent->right;                           //case 1
            }

            if (w->left->color == BLACK && w->right->color == BLACK) {
                w->color = RED;                                 //case 2
                x = x->parent;                                  //case 2
            } else if (w->right->color == BLACK) {
                w->left->color = BLACK;                         //case 3
                w->color = RED;                                 //case 3
                right_rotate(T, w);                             //case 3
                w = x->parent->right;                           //case 3
            }
            w->color = x->parent->color;                        //case 4
            x->parent->color = BLACK;                           //case 4
            w->right->color = BLACK;                            //case 4
            left_rotate(T, x->parent);                          //case 4
            x = T->root;                                        //case 4
        } else {
            if (x == x->parent->right) {
                w = x->parent->left;
                if (w->color == RED) {
                    w->color = BLACK;
                    x->parent->color = RED;
                    right_rotate(T, x->parent);
                    w = x->parent->left;
                }

                if (w->right->color == BLACK && w->left->color == BLACK) {
                    w->color = RED;
                    x = x->parent;
                } else if (w->left->color == BLACK) {
                    w->right->color = BLACK;
                    w->color = RED;
                    left_rotate(T, w);
                    w = x->parent->left;
                }
                w->color = x->parent->color;
                x->parent->color = BLACK;
                w->left->color = BLACK;
                right_rotate(T, x->parent);
                x = T->root;
            }
        }
    }
    x->color = BLACK;
}
开发者ID:codeplayer2org,项目名称:CLRS-code,代码行数:58,代码来源:rb_tree.c


示例10: k_rbtree_delete_fixup

static void
k_rbtree_delete_fixup(k_rbtree_t* t,k_rbnode_t* x)
{
        k_rbnode_t* w;// w is x's brother
        while( (x != t->root)&& (x->color == k_color_black) ){

                if(x == x->parent->left){
                        w = x->parent->right;
                        if(w->color == k_color_red){
                                w->color = k_color_black;
                                x->parent->color = k_color_red;
                                left_rotate(t, x->parent);
                                w = x->parent->left;
                        }
                        if(w->left->color == k_color_black &&
                           w->right->color == k_color_black){
                                w->color = k_color_red;
                                x = x->parent;
                        }else if (w->right->color == k_color_black){
                                w->left->color = k_color_black;
                                w->color = k_color_red;
                                right_rotate(t, w);
                                w = x->parent->right;
                        }
                        w->color = x->parent->color;
                        w->parent->color = k_color_black;
                        left_rotate(t, x->parent);
                        x = t->root;

                }else{//x == x->parent->right;
                        w = x->parent->left;
                        if(w->color == k_color_red){
                                w->color = k_color_black;
                                x->parent->color = k_color_red;
                                right_rotate(t,x->parent);
                                w = x->parent->right;
                        }
                        if(w->right->color == k_color_black &&
                           w->left->color == k_color_black){
                                w->color = k_color_red;
                                x = x->parent;
                        }else if ( w->left->color = k_color_black){
                                w->right->color = k_color_black;
                                w->color = k_color_red;
                                left_rotate(t,w);
                                w = w->parent->left;
                        }
                        w->color = x->parent->color;
                        w->parent->color = k_color_black;
                        right_rotate(t, x->parent);
                        x = t->root;

                }

        }
        x->color = k_color_black;
}
开发者ID:huangchonghai,项目名称:httpserver-4,代码行数:57,代码来源:k_rbtree.c


示例11: while

 void _redblacktree::DeleteFixup(tree *x){
     tree *w;
     while (x != root && x->color == black) {
         if (x == x->parent->left) {
             w = x->parent->right;
             if (w->color == red) {
                 w->color = black;
                 x->parent->color = red;
                 left_rotate(x->parent);
                 w = x->parent->right;
                 
             }
             if (w->left->color == black &&  w->right->color == black) {
                 w->color = red;
                 x = x->parent;
             } else {
                 if (w->right->color == black) {
                     w->left->color = black;
                     w->color = red;
                     right_rotate(w);
                     w = x->parent->right;
                 }
                 w->color = x->parent->color;
                 x->parent->color =black;
                 w->right->color = black;
                 left_rotate(x->parent);
                 x = root;
             }
         } else {
             w = x->parent->right;
             if (w->color == red) {
                 w->color = black;
                 x->parent->color = red;
                 right_rotate(x->parent);
                 w = x->parent->left;
                 
             }
             if (w->right->color == black &&  w->left->color == black) {
                 w->color = red;
                 x = x->parent;
             } else {
                 if (w->left->color == black) {
                     w->right->color = black;
                     w->color = red;
                     left_rotate(w);
                     w = x->parent->left;
                 }
                 w->color = x->parent->color;
                 x->parent->color =black;
                 w->left->color = black;
                 right_rotate(x->parent);
                 x = root;
             }
         }
     }
     x->color = black;
 }
开发者ID:powernano,项目名称:Alloc,代码行数:57,代码来源:_redblacktree.cpp


示例12: rb_delete_fixup

void rb_delete_fixup(rbt *T, rbn *x)
{
	rbn *w, *y;
	while (x != T->root && x->color == BLACK)
	{
		if (x == x->p->left) {
			w = x->p->right;
			if (w->color == RED) {
				w->color = BLACK;
				x->p->color = RED;
				left_rotate(T, x->p);
				w = x->p->right;
			}
			if (w->left->color == BLACK && w->right->color == BLACK) {
				w->color = RED;
				x = x->p;
			} else {
				if (w->right->color == BLACK) {
					w->left->color = BLACK;
					w->color = RED;
					right_rotate(T, w);
					w = x->p->right;
				}
				w->color = x->p->color;
				x->p->color = BLACK;
				w->right->color = BLACK;
				left_rotate(T, x->p);
				x = T->root;
			}
		} else {
			w = x->p->left;
			if (w->color == RED) {
				w->color = BLACK;
				x->p->color = RED;
				right_rotate(T, x->p);
				w = x->p->left;
			}
			if (w->left->color == BLACK && w->right->color == BLACK) {
				w->color = RED;
				x = x->p;
			} else {
				/*dbg(x, w);*/
				if (w->left->color == BLACK) {
					w->right->color = BLACK;
					w->color = RED;
					left_rotate(T, w);
					w = x->p->left;
				}
				w->color = x->p->color;
				x->p->color = BLACK;
				w->left->color = BLACK;
				right_rotate(T, x->p);
				x = T->root;
			}
		}
	}
}
开发者ID:LinuxKernelDevelopment,项目名称:ITA,代码行数:57,代码来源:rbtree.c


示例13: rbt_fix

static rbt rbt_fix(rbt r)
{
  if(IS_RED(r->left) && IS_RED(r->left->left)){
    if(IS_RED(r->right)){
      /*colour root red and children a,b black*/
      r->colour = RED;
      r->left->colour = BLACK;
      r->right->colour = BLACK;
    }else if(IS_BLACK(r->right)){
      /*right rotate root , colour new root (a) black, and new child(old root) red*/
      r = right_rotate(r);
      r->colour = BLACK;
      r->right->colour = RED;/*old root?*/
    }
  }else if(IS_RED(r->left) && IS_RED(r->left->right)){
    if(IS_RED(r->right)){
      /*colour root red and children a,b black*/
      r->colour = RED;
      r->left->colour = BLACK;
      r->right->colour = BLACK;
    }
    else if(IS_BLACK(r->right)){
      /*left rotate left child (a), right rotate root (r),colour new root (d) black and new child (R) red*/
      r->left = left_rotate(r->left);
      r = right_rotate(r);
      r->colour = BLACK;
      r->right->colour = RED;/*old root?*/
    }
  }else if(IS_RED(r->right) && IS_RED(r->right->left)){
    if(IS_RED(r->left)){
      /* colour root (R) red and children (a,b) black*/
      r->colour = RED;
      r->left->colour = BLACK;
      r->right->colour = BLACK;
    }else if(IS_BLACK(r->left)){
      /*right rotate right child(b),left rotate root(r),colour new root (e) black and new child (r) red*/
      r->right = right_rotate(r->right);
      r = left_rotate(r);
      r->colour = BLACK;
      r->left->colour = RED;/*old root?*/
    }
  }else if(IS_RED(r->right) && IS_RED(r->right->right)){
    if(IS_RED(r->left)){
      /*colour root (R) red and children (A,B) black*/
      r->colour = RED;
      r->left->colour = BLACK;
      r->right->colour = BLACK;
    }
    else if(IS_BLACK(r->left)){
      /*left rotate root R, colour new root b black and new child R red*/
      r = left_rotate(r);
      r->colour = BLACK;
      r->left->colour = RED;/*old root?*/
    }
  }
  return r;
}
开发者ID:lchish,项目名称:cosc,代码行数:57,代码来源:rbt.c


示例14: delete_fixup

static void
delete_fixup(struct rbtree *rbt, struct rbnode *nd)
{
    struct rbnode *tmp = &rbt->nil;
    while (nd != rbt->root && nd->color == BLACK)
        if (nd == nd->parent->left) {
            tmp = nd->parent->right;
            if (tmp->color == RED) {
                tmp->color = BLACK;
                nd->parent->color = RED;
                left_rotate(rbt, nd->parent);
                tmp = nd->parent->right;
            }
            if (tmp->left->color == BLACK && tmp->right->color == BLACK) {
                tmp->color = RED;
                nd = nd->parent;
            } else {
                if (tmp->right->color == BLACK) {
                    tmp->left->color = BLACK;
                    tmp->color = RED;
                    right_rotate(rbt, tmp);
                    tmp = nd->parent->right;
                }
                tmp->color = nd->parent->color;
                nd->parent->color = BLACK;
                tmp->right->color = BLACK;
                left_rotate(rbt, nd->parent);
                nd = rbt->root; //end while
            }
        } else {
            tmp = nd->parent->left;
            if (tmp->color == RED) {
                tmp->color = BLACK;
                nd->parent->color = RED;
                right_rotate(rbt, nd->parent);
                tmp = nd->parent->left;
            }
            if (tmp->right->color == BLACK && tmp->left->color == BLACK) {
                tmp->color = RED;
                nd = nd->parent;
            } else {
                if (tmp->left->color == BLACK) {
                    tmp->right->color = BLACK;
                    tmp->color = RED;
                    left_rotate(rbt, tmp);
                    tmp = nd->parent->left;
                }
                tmp->color = nd->parent->color;
                nd->parent->color = BLACK;
                tmp->left->color = BLACK;
                right_rotate(rbt, nd->parent);
                nd = rbt->root; //end while
            }
        }
    nd->color = BLACK;
}
开发者ID:RocFang,项目名称:dnspod-sr,代码行数:56,代码来源:storage.c


示例15: while

void SplayTree<T>::splay(SplayNode<T> *x, SplayNode<T> *y)
{
    while(x->father != y)
    {
        SplayNode<T> * p = x->father;

        if (p->father == y)
        {
            // 因为p的父亲是y,所以只需要Zig操作,就可以使得x的父亲变成y
            if (p->left == x)
            {
                right_rotate(x);
            }
            else
            {
                left_rotate(x);
            }
        }
        else
        {
            SplayNode<T> * g = p->father;

            if (g->left == p)
            {
                if (p->left == x)
                {
                    // x, p同为左儿子,zig-zig操作
                    right_rotate(p);
                    right_rotate(x);
                }
                else
                {
                    //p为左, x为右,zig-zag操作
                    left_rotate(x);
                    right_rotate(x);
                }
            }
            else
            {
                if (p->right == x)
                {
                    // x, p同为右儿子,zig-zig操作
                    left_rotate(p);
                    left_rotate(x);
                }
                else
                {
                    //p为右, x为左,zig-zag操作
                    right_rotate(x);
                    left_rotate(x);
                }

            }
        }
    }
}
开发者ID:HappyShadowWalker,项目名称:HihoCode,代码行数:56,代码来源:splay_tree.cpp


示例16: bbtree_insert_fixup

static void bbtree_insert_fixup( bbtree_t *tree,
                                 bbtree_node_t *node )
{
    bbtree_node_t *node2;
    bbtree_node_t *nil = &tree->nil;

    while (node != tree->root && node->parent->colour == BBTREE_RED)
    { 
        if (node->parent == node->parent->parent->left)
        { 
            node2 = node->parent->parent->right;
            if (node2 != nil && node2->colour == BBTREE_RED)
            { 
                node->parent->colour = BBTREE_BLACK;
                node2->colour = BBTREE_BLACK;
                node->parent->parent->colour = BBTREE_RED;
                node = node->parent->parent;
            }
            else
            {
                if (node == node->parent->right)
                {
                    node = node->parent;
                    left_rotate( tree, node );
                }
                node->parent->colour = BBTREE_BLACK;
                node->parent->parent->colour = BBTREE_RED;
                right_rotate( tree, node->parent->parent );
            }
        }
        else
        {
            node2 = node->parent->parent->left;
            if (node2 != nil && node2->colour == BBTREE_RED)
            { 
                node->parent->colour = BBTREE_BLACK;
                node2->colour = BBTREE_BLACK;
                node->parent->parent->colour = BBTREE_RED;
                node = node->parent->parent;
            }
            else
            {
                if (node == node->parent->left)
                {
                    node = node->parent;
                    right_rotate( tree, node );
                }
                node->parent->colour = BBTREE_BLACK;
                node->parent->parent->colour = BBTREE_RED;
                left_rotate( tree, node->parent->parent );
            }
        }
    }
    tree->root->colour = BBTREE_BLACK;
}
开发者ID:wodz,项目名称:open21xx,代码行数:55,代码来源:bbtree.c


示例17: fix_rb_tree

void fix_rb_tree(struct node **root, struct node *z)
{
	struct node *y;
	while(z->parent->color == RED)
	{
		if(z->parent == z->parent->parent->left)
		{
			y = z->parent->parent->right;
			if(y != NIL && y->color == RED)
			{
				//Case 1.1
				z->parent->color = y->color = BLACK;
				z->parent->parent->color = RED;
				z = z->parent->parent;
			}
			else //Segmentation fault should come
			{
				if(z == z->parent->right)
				{
					//Case 1.2
					z = z->parent;
					left_rotate(root, z);
				}
				//Case 1.3
				z->parent->color = BLACK;
				z->parent->parent->color = RED;
				right_rotate(root, z->parent->parent);
			}
		}
		else
		{
			y = z->parent->parent->left;
			if(y != NIL && y->color == RED)
			{
				//Case 2.1
				z->parent->color = y->color = BLACK;
				z->parent->parent->color = RED;
				z = z->parent->parent;
			}
			else
			{
				if(z == z->parent->left)
				{
					//Case 2.2
					z = z->parent;
					right_rotate(root, z);
				}
				z->parent->color = BLACK;
				z->parent->parent->color = RED;
				left_rotate(root, z->parent->parent);
			}
		}
	}
	(*root)->color = BLACK;
}
开发者ID:MomentSeeker,项目名称:clrs,代码行数:55,代码来源:red_black_tree.c


示例18: rb_insert_fixup

void rb_insert_fixup(Node* &T, Node *n)
{
	// 如果n的父亲是红色,则需要调整
	// 如果n的父亲是黑色,则不需要调整,因为n本身是红色
	while(IS_RED(PARENT(n))) {
		// 根据n的叔叔节点的颜色,来决定调整方案
		Node *p = IS_LEFT(PARENT(n))? RIGHT(PARENT(PARENT(n))): LEFT(PARENT(PARENT(n)));

		// 如果叔叔是红色,那很简单,把爷爷的黑色转移给父亲和叔叔,爷爷刷成红色
		// 这样,即满足了性质4,也没有破坏性质5及其他性质
		// 但是,爷爷可能破坏了红黑性质4,则从爷爷开始继续调整(向上递归了两层)
		if (IS_RED(p)) {
			// 父亲刷成黑色
			SET_BLACK(PARENT(n));
			// 叔叔刷成黑色
			SET_BLACK(p);
			// 爷爷刷成红色
			SET_RED(PARENT(PARENT(n)));

			// 从爷爷开始继续调整
			n = PARENT(PARENT(n));
			continue;
		} 

		// 如果叔叔是黑色,就复杂一点,引入旋转操作
		// 如果n是左孩子,那么需要一次右旋+颜色调整即可
		// 如果n是右孩子,则通过一次左旋调整成左孩子,然后按上面情况处理
		if (IS_LEFT(PARENT(n))) { 
			// 如果n是右孩子,通过右旋调整成左孩子
			if (IS_RIGHT(n)) {
				n = PARENT(n);
				left_rotate(T, n);
			}

			// 现在n是左孩子了
			SET_BLACK(PARENT(n));
			SET_RED(PARENT(PARENT(n)));
			right_rotate(T, PARENT(PARENT(n)));
		} else {
			if (IS_LEFT(n)) {
				n = PARENT(n);
				right_rotate(T,n);
			}
			SET_BLACK(PARENT(n));
			SET_RED(PARENT(PARENT(n)));
			left_rotate(T,PARENT(PARENT(n)));
		}
	}
	
	// 如果n是根节点,则把根设置为黑色
	if (NIL == PARENT(n))
		SET_BLACK(n);
}
开发者ID:jarfield,项目名称:SolutionToCLR2nd,代码行数:53,代码来源:tree.cpp


示例19: while

void RBTree::rb_insert_fixup(Node *nd)
{
	Node *y;
	while(nd->parent->color == RED)
	{
		if(nd->parent == nd->parent->parent->left)
		{
			y = nd->parent->parent->right;
			if(y->color == RED)//右叔叔是RED
			{
				nd->parent->color = BLACK;
				y->color = BLACK;
				nd->parent->parent->color = RED;
				nd = nd->parent->parent;
			}
			else //右叔叔是BLANK
			{
				if(nd == nd->parent->right)
				{
					nd = nd->parent;
					left_rotate(nd);
				}
				nd->parent->color = BLACK;
				nd->parent->parent->color = RED;
				right_rotate(nd->parent->parent);
			}
		}
		else
		{
			y = nd->parent->parent->left;
			if(y->color == RED)//左叔叔是RED
			{
				y->color = BLACK;
				nd->parent->color = BLACK;
				nd->parent->parent->color = RED;
				nd = nd->parent->parent;
			}
			else			  //左叔叔是BLANK
			{
				if(nd == nd->parent->left)
				{
					nd = nd->parent;
					right_rotate(nd);
				}

				nd->parent->color = BLACK;
				nd->parent->parent->color = RED;
				left_rotate(nd->parent->parent);
			}
		}
	}
	root->color = BLACK;
}
开发者ID:wyg031113,项目名称:mycode,代码行数:53,代码来源:rbtree.cpp


示例20: while

void RB::rb_balance(rb_node *x)
{
	x->color = rb_red;
	while (x != root && x->parent->color == rb_red)
	{
		rb_node *y = 0;
		if (x->parent == x->parent->parent->left)
		{
			y = x->parent->parent->right;
			if (y && y->color == rb_red)
			{
				y->color = rb_black;
				x->parent->parent->color = rb_red;
				x->parent->color = rb_black;
				x = x->parent->parent;
			}
			else
			{
				if (x == x->parent->right)
				{
					x = x->parent;
					left_rotate(x);
				}
				x->parent->color = rb_black;
				x->parent->parent->color = rb_red;
				right_rotate(x->parent->parent);
			}
		}
		else
		{
			y = x->parent->parent->left;
			if (y && y->color == rb_red)
			{
				y->color = rb_black;
				x->parent->color = rb_black;
				x->parent->parent->color = rb_red;
				x = x->parent->parent;
			}
			else
			{
				if (x == x->parent->left)
				{
					x = x->parent;
					right_rotate(x);
				}
				x->parent->color = rb_black;
				x->parent->parent->color = rb_red;
				left_rotate(x->parent->parent);
			}
		}
	}
	root->color = rb_black;
}
开发者ID:qphien,项目名称:pat,代码行数:53,代码来源:RB_Tree.cpp



注:本文中的right_rotate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rindex函数代码示例发布时间:2022-05-30
下一篇:
C++ rig_debug函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap