Skip to content

Commit

Permalink
improving and reducing cost of sorting 3 nbrs
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed Jun 7, 2024
1 parent bcd7f4c commit 2ec33ad
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions program_to_test/src/ft_sort_until3.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2ec33ad

Please sign in to comment.