aboutsummaryrefslogtreecommitdiff
path: root/src/rbt/ft_rbtrotate_right.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-26 21:04:43 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-26 21:04:43 +0200
commita3c962abbcdae671b886c4c76ddb9bb8ac27c958 (patch)
tree7039b39f9fa56b9ad6e3b1c347fb5b77c049cada /src/rbt/ft_rbtrotate_right.c
parent65c5d5157e890e9f9445a94fb2d7f660e5492d8e (diff)
downloadlibft-a3c962abbcdae671b886c4c76ddb9bb8ac27c958.tar.gz
libft-a3c962abbcdae671b886c4c76ddb9bb8ac27c958.tar.bz2
libft-a3c962abbcdae671b886c4c76ddb9bb8ac27c958.zip
Added ft_btsorted_insert, ft_btsorted_search, Red-black tree struct (not tested)
Diffstat (limited to 'src/rbt/ft_rbtrotate_right.c')
-rw-r--r--src/rbt/ft_rbtrotate_right.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/rbt/ft_rbtrotate_right.c b/src/rbt/ft_rbtrotate_right.c
new file mode 100644
index 0000000..46d72e2
--- /dev/null
+++ b/src/rbt/ft_rbtrotate_right.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_rbtrotate_right.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/26 18:10:57 by charles #+# #+# */
+/* Updated: 2020/04/26 20:27:53 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_rbt.h"
+
+/*
+** \brief Rotate a red-black tree to the right
+** \param tree Pointer to Pointer to a red-black tree
+**
+** 10 5
+** / \ / \
+** 5 11 --> 4 10
+** / \ / \
+** 4 6 6 11
+*/
+
+void ft_rbtrotate_right(t_ftrbt **tree)
+{
+ t_ftrbt *new_root;
+ t_ftrbt *tmp;
+
+ if (tree == NULL || *tree == NULL || (*tree)->left == NULL)
+ return ;
+ new_root = (*tree)->left;
+ tmp = new_root->right;
+ new_root->right = *tree;
+ (*tree)->left = tmp;
+ *tree = new_root;
+}