前端之家收集整理的这篇文章主要介绍了
【数据结构】伸展树 Splay,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
// 平衡树 splay 模板
void rotate( int i )
{
int D = dad[i],G = dad[D],S = son[i][ !typ[i] ];
son[G][ typ[D] ] = i,dad[S] = D;
son[D][ typ[i] ] = S,dad[D] = i;
son[i][ !typ[i] ] = D,dad[i] = G;
typ[S] = typ[i],typ[i] = typ[D],typ[D] = !typ[S];
update( D );
}
void splay( int i )
{
while( typ[i] != 2 )
{
if( typ[ dad[i] ] != 2 )
if( typ[i] == typ[ dad[i] ] ) rotate( dad[i] ); else rotate( i );
rotate( i );
}
update( i );
}
原文链接:https://www.f2er.com/datastructure/383213.html