Big white book stretching tree learning notes, big white stretching learning notes

Source: Internet
Author: User

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.