Cześć, napisałem funkcję rotującą drzewo BST mam tylko problem kiedy chciałbym działać na korzeniu. Poddrzewo lewe czy prawe normalnie rotuje, ale kiedy chcę użyć funkcji na korzeniu program się wywala albo tracę elementy drzewa.Jak mogę to poprawić?
struct tree_node *rotation_left(struct tree_node*root,struct tree_node*R)
{
struct tree_node *y= (struct tree_node *)malloc(sizeof(struct tree_node));
if(R->right_child)
{
y=R->right_child;
R->right_child=y->left_child;
if(y->left_child)
y->left_child->parent=R;
y->parent=R->parent;
if(R->parent==NULL)
root=y;
else if(R==R->parent->left_child)
R->parent->left_child=y;
else
R->parent->right_child=y;
y->left_child=R;
R->parent=y;
}
return R;
};