From 4652a276ff53cc56863e26a3c6f852637257a959 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 8 Jul 2020 20:58:15 -0400 Subject: Add rotate functions for map trees --- collections/map/map.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/collections/map/map.c b/collections/map/map.c index 747d6ce..f5751b5 100644 --- a/collections/map/map.c +++ b/collections/map/map.c @@ -37,6 +37,32 @@ struct map_node *root; return map_height(root->right) - map_height(root->left); } +void map_rotate_left(node) +struct map_node **node; +{ + struct map_node *tmp; + + tmp = *node; + *node = tmp->right; + tmp->right = (*node)->left; + (*node)->left = tmp; + + return; +} + +void map_rotate_right(node) +struct map_node **node; +{ + struct map_node *tmp; + + tmp = *node; + *node = tmp->left; + tmp->left = (*node)->right; + (*node)->right = tmp; + + return; +} + map* map_new(cmp) cmp_func cmp; { -- cgit v1.1