Splay* splay(Splay* &Root) {
		Splay *y,*z,*rf=Root->fa;
		while (fa!=rf) {
			y=fa; z=y->fa;
			if (z==null) this==y->l?zig():zag(); else
			if (y==z->l) this==y->l?(y->zig(),zig()):(zag(),zig());
			        else this==y->r?(y->zag(),zag()):(zig(),zag());
		}
		updata();
		return Root=this;
	}
	Splay* splay() {
		Splay *y,*z;
		if (this==null) return this;
		while (fa!=null) {
			y=fa; z=y->fa;
			if (z==null) this==y->l?zig():zag(); else
			if (y==z->l) this==y->l?(y->zig(),zig()):(zag(),zig());
			        else this==y->r?(y->zag(),zag()):(zig(),zag());
		}
		update();
		return this;
	}
Beispiel #3
0
splay_tree splay (splay_tree node)
{
    while (node->parent != NULL)
    {
        if (node->parent->parent != NULL)
        {
            if (node->parent->parent->lchild == node->parent) // left
            {
                if (node->parent->lchild == node)  // left-left
                {
                   node->parent = zig(node->parent);
                   node = zig(node);
                }
                else                               // left-right
                {
                    node = zag(node);
                    node = zig(node);
                }
            }
            else                                   // right
            {
                if (node->parent->rchild == node)  // right-right
                {
                    node->parent = zag(node->parent);
                    node = zag(node);
                }
                else                               // right-left
                {
                    node = zig(node);
                    node = zag(node);
                }

            }
        }
        else
        {
            if (node->parent->lchild = node)  // left
            {
                node = zig(node);
            }
            else                               // right
            {
                node = zag(node);
            }
        }

    }

    return node;
}
Beispiel #4
0
void splay(node *p)
{
    while (p->p != NULL) {
        reverse(p->p->p);
        reverse(p->p);
        reverse(p);
        if (p->p->p == NULL) {
            if (p == p->p->l) {
                zig(p);
            }
            else {
                zag(p);
            }
        }
        else if (p->p == p->p->p->l) {
            if (p == p->p->l) {
                zigzig(p);
            }
            else {
                zagzig(p);
            }
        }
        else {
            if (p == p->p->l) {
                zigzag(p);
            }
            else {
                zagzag(p);
            }
        }
    }
}
inline void splay(int &root,int x)
{
    for (int y,z;Par(x);)
    {
        y=Par(x),z=Par(y);
        if (!z)
            if (Lch(y)==x)    zig(x);
            else    zag(x);
        else
        if (Lch(z)==y)
            if (Lch(y)==x)    zig(y),zig(x);
            else    zag(x),zig(x);
        else
            if (Rch(y)==x)    zag(y),zag(x);
            else    zig(x),zag(x);
    }
    Tupdate(root=x);
}
void turnup(long pp)
{
	if (f[pp]==0) return;
	if (r[pp]>=r[f[pp]]) return;
	if (p[0][f[pp]]==pp)
	{
		zig(pp);
		turnup(pp);
		return;
	}
	if (p[1][f[pp]]==pp)
	{
		zag(pp);
		turnup(pp);
		return;
	}
	pp=pp/(pp-pp);
}
Beispiel #7
0
void treapins(number * & p,ll pl,ll pr,number * np){
   if(!p )
   {
    tisp = p = np;
    np->lc = np->rc = NULL;
   }
   else{
     int c = numxcmp(np,p);
     if(c < 0){
      treapins(p->lc,pl,p->id-1,np);
      if(p->lc->pri < p->pri) zig(p);
     }
     else if(c > 0)
     {
      treapins(p->rc,p->id+1,pr,np);
      if(p->rc->pri < p->pri)
       zag(p);
     }
     else
      tisp = p;
   }
   if(p == np)
    tispl = pl,tispr = pr;
}
inline void rotate(root& o, int d) {
    d? zig(o): zag(o);
    d? o->rson->maintain(): o->lson->maintain();
    o->maintain();
}
Beispiel #9
0
void zagzag(node* p)
{
    zag(p->p);
    zag(p);
}
Beispiel #10
0
void zagzig(node* p)
{
    zag(p);
    zig(p);
}
Beispiel #11
0
void zigzag(node* p)
{
    zig(p);
    zag(p);
}
Beispiel #12
0
void splay(SPTNode *T){
	SPTNode *p = T;
	while(p&&p->father){
		p->value < p->father->value ? zig(p) : zag(p);
	}
}
struct elem * post_del(struct elem *const e) {
	int b;
	if (!e) return NULL;
	update(e), b = balance_factor(e);
	return b > 1 ? (balance_factor(e->left) >= 0 ? zig(e) : (e->left = zag(e->left), zig(e))) : b < -1 ? (balance_factor(e->right) <= 0 ? zag(e) : (e->right = zig(e->right), zag(e))) : e; 
}
struct elem * ins(struct elem *const e, const KEY_T key) {
	int b;
	if (!e) return new_elem(key);
	if (e->key == key) return e;
	if (key < e->key) e->left = ins(e->left, key); else e->right = ins(e->right, key);
	update(e), b = balance_factor(e);
	return b > 1 && key < e->left->key ? zig(e) : b > 1 && key > e->left->key ? (e->left = zag(e->left), zig(e)) : b < -1 && key > e->right->key ? zag(e) : b < -1 && key < e->right->key ? (e->right = zig(e->right), zag(e)) : e;
}