From 2ec33ad293f27765b45f1fc556a392f4909cc658 Mon Sep 17 00:00:00 2001 From: umeneses Date: Fri, 7 Jun 2024 10:41:12 -0300 Subject: [PATCH] improving and reducing cost of sorting 3 nbrs --- program_to_test/src/ft_sort_until3.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/program_to_test/src/ft_sort_until3.c b/program_to_test/src/ft_sort_until3.c index 3a359eb..f002d2a 100644 --- a/program_to_test/src/ft_sort_until3.c +++ b/program_to_test/src/ft_sort_until3.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 12:19:14 by umeneses #+# #+# */ -/* Updated: 2024/06/06 18:13:37 by umeneses ### ########.fr */ +/* Updated: 2024/06/07 10:39:41 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,19 +40,22 @@ t_stack *ft_sort_3_nbrs(t_stack **list) while (!ft_is_sorted(*list)) { if (((*list)->nbr < (*list)->next->nbr) + && ((*list)->nbr < ft_lst_goto_end(*list)->nbr) + && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr)) + ft_do_reverse_rotate_a(list); + else if (((*list)->nbr < (*list)->next->nbr) + && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr) && ((*list)->nbr > ft_lst_goto_end(*list)->nbr)) ft_do_reverse_rotate_a(list); - if (((*list)->next->nbr < (*list)->nbr) + else if (((*list)->nbr > (*list)->next->nbr) + && ((*list)->nbr > ft_lst_goto_end(*list)->nbr) && ((*list)->next->nbr < ft_lst_goto_end(*list)->nbr)) ft_do_rotate_a(list); - if (((*list)->nbr < ft_lst_goto_end(*list)->nbr) - && ((*list)->nbr < ft_lst_goto_before_end(*list)->nbr)) - { - ft_do_swap_a(list); + else if (((*list)->nbr > ft_lst_goto_end(*list)->nbr) + && ((*list)->nbr > (*list)->next->nbr) + && ((*list)->next->nbr > ft_lst_goto_end(*list)->nbr)) ft_do_rotate_a(list); - } - if ((ft_lst_goto_head(*list)->nbr > ft_lst_goto_head(*list)->next->nbr) - && (ft_lst_goto_head(*list)->nbr > ft_lst_goto_end(*list)->nbr)) + else ft_do_swap_a(list); } return (*list);