From a3c962abbcdae671b886c4c76ddb9bb8ac27c958 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 26 Apr 2020 21:04:43 +0200 Subject: Added ft_btsorted_insert, ft_btsorted_search, Red-black tree struct (not tested) --- src/rbt/ft_rbtrotate_left.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/rbt/ft_rbtrotate_left.c (limited to 'src/rbt/ft_rbtrotate_left.c') diff --git a/src/rbt/ft_rbtrotate_left.c b/src/rbt/ft_rbtrotate_left.c new file mode 100644 index 0000000..7cff65d --- /dev/null +++ b/src/rbt/ft_rbtrotate_left.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rbtrotate_left.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/26 18:03:35 by charles #+# #+# */ +/* Updated: 2020/04/26 20:27:44 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_rbt.h" + +/* +** \brief Rotate a red-black tree to the left +** \param tree Pointer to Pointer to a red-black tree +** +** 5 10 +** / \ / \ +** 4 10 --> 5 11 +** / \ / \ +** 6 11 4 6 +*/ + +void ft_rbtrotate_left(t_ftrbt **tree) +{ + t_ftrbt *new_root; + t_ftrbt *tmp; + + if (tree == NULL || *tree == NULL || (*tree)->right == NULL) + return ; + new_root = (*tree)->right; + tmp = new_root->left; + new_root->left = *tree; + (*tree)->right = tmp; + *tree = new_root; +} -- cgit