Big white book stretching tree learning notes, big white stretching learning notes
Void splay (Node * & o, int k)
{
Int d = o-> cmp (k); // The cmp function compares the values of k and o-> ch [0]-> s + 1.
If (d = 1) k-= o-> ch [0]-> s + 1;
If (d! =-1)
{
Node * p = o-> ch [d];
Int d2 = p-> cmp (k );
Int k2 = (d2 = 0? K: k-p-> ch [0]-> s-1 );
If (d2! =-1)
{
Splay (p-> ch [d2], k2 );
If (d = d2) rotate (o, d ^ 1);/* at this time, k nodes have been stretched to, p-> ch [d2], three points for d = d2
First, you can rotate o to the d ^ 1 direction of o. Then, o points to p, and then o rotates in the same direction, this rotation method is used to rotate x's Father's Day point first in the book.
The effect of rotating x is the same.
*/
Else rotate (o-> ch [d], d);/* when d! = D2 indicates that the three points are not collocated. p-> ch [d2] is rotated to the position of p, and then rotated to d and book at the node o.
As mentioned above, when the three points are not in the same line, the opposite rotation of x is the same effect.
*/
}
Rotate (o, d ^ 1 );
}
}