Great White Book Stretching tree study notes

Source: Internet
Author: User

void Splay (Node * &o,int k)
{
int d=o->cmp (k); The//CMP function compares the sizes 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),/* This time has extended the K-node to, P->ch[d2], when D==d2, stating three points
Collinear, you can first turn o to o d^1 direction, then O Point is P, and then let O in the same direction rotation once, this way of rotation and the book said first rotation x Father node
The effect of rotating x again is the same.
*/
else rotate (o->ch[d],d);/* When D!=d2, the three point is not collinear, then p->ch[d2] rotate to the position of P then, then in the O for the node to D rotation and the book
When the three points are not collinear, the rotation of the opposite rotation two times X is the same effect
*/
}
Rotate (o,d^1);
}
}

Great White Book Stretching tree study notes

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.