您的位置:首页 > 其它

splay旋转模板

2016-04-20 20:49 295 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: