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 = =