码迷,mamicode.com
首页 > 其他好文 > 详细

splay旋转模板

时间:2016-04-22 20:26:18      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

splay旋转模板

void rotate(int x) {
    int y=f[x],z=son(x);f[x]=f[y];
    if (f[x]) t[f[x]][son(y)]=x;
    t[y][z]=t[x][1-z];
    if (t[x][1-z]) f[t[x][1-z]]=y;
    f[y]=x;t[x][1-z]=y;
}
void splay(int x,int y) {
    while (f[x]!=y) {
        if (f[f[x]]!=y)
            if (son(f[x])==son(x)) rotate(f[x]);
            else rotate(x);
        rotate(x); 
    }
    if (!y) root=x;
}

splay旋转模板

标签:

原文地址:http://blog.csdn.net/alan_cty/article/details/51204007

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!