







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








CPSC 223 -‐-‐ Fall 2010
CPSC 223 -‐-‐ Fall 2010
CPSC 223 -‐-‐ Fall 2010
CPSC 223 -‐-‐ Fall 2010
// return new root after left-left rotation Node* rotateWithLeftChild(Node* k2) { ... } // return new root after right-right subtree Node* rotateWithRightChild(Node* k1) { … } CPSC 223 -‐-‐ Fall 2010
// return new root after left-left rotation Node* rotateWithLeftChild (Node* k2) { Node* k1 = k2->leftChild; k2->leftChild = k1->rightChild; k1->rightChild = k2; return k1; } CPSC 223 -‐-‐ Fall 2010
// return new root after right-right rotation Node* rotateWithRightChild (Node* k1) { Node * k2 = k1->rightChild; k1->rightChild = k2->leftChild; k2->leftChild = k1; return k2; } CPSC 223 -‐-‐ Fall 2010
CPSC 223 -‐-‐ Fall 2010 k 3 b = 0 or 1^ k 2 b = 2 D A B k 1 C b = 1 or 2 Double rota-on (le/-‐right case) Second rota-on k 2 k 3 A B D k 1 C
// return new root of left-right rotation Node* doubleRotateWithLeftChild (Node* k3) { ... } CPSC 223 -‐-‐ Fall 2010
// return new root of left-right rotation Node* doubleRotateWithLeftChild (Node* k3) { k3->leftChild = rotateWithRightChild(k3->leftChild); return rotateWithLeftChild(k3); } CPSC 223 -‐-‐ Fall 2010
// return new root of right-left rotation Node* doubleRotateWithRightChild (Node* k1) { k1->rightChild = rotateWithLeftChild (k1->rightChild); return rotateWithRightChild (k1); } CPSC 223 -‐-‐ Fall 2010