Splay Bug Version = =

Source: Internet
Author: User

1 structSplay_node {2Splay_node *left, *Right ;3     intvalue;4 };5 intsize;6 7splay_node* splay (splay_node* A,intv) {8Splay_node B, *l, *r, *y;9     if(A = = NULL)returnA;TenB.left = B.right =NULL; OneL = R = &b; A      while(1) { -         if(V < a->value) { -             if(A->left = =NULL) { the                  Break; -             } -             if(V < a->left->value) { -y = a->Left ; +A->left = y->Right ; -Y->right =A; +A =y; A                 if(A->left = =NULL) { at                      Break; -                 } -             } -R->left =A; -R =A; -A = a->Left ; in}Else if(V > a->value) { -             if(A->right = =NULL) { to                  Break; +             } -             if(V > a->right->value) { they = a->Right ; *A->right = y->Left ; $Y->left =A;Panax NotoginsengA =y; -                 if(A->right = =NULL) { the                      Break; +                 } A             } theL->right =A; +L =A; -A = a->Right ; $}Else { $              Break; -         } -     } theL->right = a->Left ; -R->left = a->Right ;WuyiA->left =B.right; theA->right =B.left; -     returnA; Wu } -  Aboutsplay_node* Splay_insert (splay_node* A,intv) { $Splay_node *node =NewSplay_node; -Node->value =v; -     if(A = =NULL) { -Node->left = Node->right =NULL; ASize =1; +         returnnode; the     } -A =Splay (A, v); $     if(V < a->value) { theNode->left = a->Left ; theNode->right =A; theA->left =NULL; thesize++; -         returnnode; in}Else if(V > a->value) { theNode->right = a->Right ; theNode->left =A; AboutA->right =NULL; thesize++; the         returnnode; the}Else { +         Deletenode; -         returnA; the     }Bayi } the  the intSplay_getmin (splay_node*a) { -     if(A->left = = NULL)returnA->value; -     returnSplay_getmin (a->Left ); the } the  the intSplay_getmax (splay_node*a) { the     if(A->right = = NULL)returnA->value; -     returnSplay_getmin (a->Right ); the } the  thesplay_node* Splay_delete (splay_node* A,intv) {94splay_node*x; the     if(A = =NULL) { the         returnNULL; the     }98A =Splay (A, v); About     if(v = = a->value) { -         if(A->left = =NULL) {101x = a->Right ;102}Else {103x = splay (A->left, Splay_getmax (a->Left ));104X->right = a->Right ; the         }106size--;107         DeleteA;108         returnx;109     } the     returnA;111}

Splay Bug Version = =

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.