AVL Tree: A two-fork search tree with equilibrium conditions, that is, an AVL tree is a two-fork lookup tree with a maximum difference of 1 of the height of the Saozi right subtree of each node. It is common to maintain the balance of the AVL tree through single rotate and double rotate.
The AVL tree is implemented as follows:
1) Single Rotate
2) Double Rotate
1) Single Rotate (singlerotatewithright)
Static Position singlerotatewithleft (Position K2) {Position K1; K1=k2-> left; K2->left=k1-> Right; K1->right=K2; K2->height=max (height (k2->left), height (k2->right)) +1; K1->height=max (height (k1->left), height (k1->right)) +1; return K1;}
2) Double Rotate (doublerotatewithright)
Static Position doublerotatewithleft (Position K3) {K3->left=singlerotatewithright (k3-> left); return Singlerotatewithleft (K3);}
The rotation implementation of the AVL tree