Czy mógłbym prosić o zerknięcie na kod poniżej?
Jest to procedura wykonująca lewą rotację w drzewie AVL. Działa w 80% przypadków...
Na razie testowałem ją na zwykłym drzewie, nie sprawdzając jeszcze wag. Zawsze lepiej, jak spojrzy ktoś z boku. Byłbym wdzięczny za pomoc.
void rotLeft(binTreeNode **subTreeRoot) { /* performs left rotation for a given subtree */
binTreeNode *tmp = *subTreeRoot; /* saving address of old root */
if ((*subTreeRoot) -> right != NULL) { /* (0) rotation can be done if root subtree exists */
*subTreeRoot = (*subTreeRoot) -> right; /* (1) right son is set as new root */
(*subTreeRoot) -> parent = tmp -> parent; /* proper parent setting */
tmp -> right = (*subTreeRoot) -> left; /* (2) right son of old root points to left son of new root */
tmp -> right -> parent = tmp; /* proper parent setting */
(*subTreeRoot) -> left = tmp; /* (3) left son of new root points to old root */
(*subTreeRoot) -> left -> parent = (*subTreeRoot); /* proper parent setting */
}
/* x <- subTreeRoot x z <- subTreeRoot
/ \ / \ / \
y z y z <- subTreeRoot x z <- subTreeRoot x b
/ \ / \ / \ / \ / \
a b a b y a b y a
(0) (1) (2) (3) */
}