diff --git a/program_to_test/headers/push_swap.h b/program_to_test/headers/push_swap.h index 027a5f3..2ba240b 100644 --- a/program_to_test/headers/push_swap.h +++ b/program_to_test/headers/push_swap.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/08 15:23:33 by umeneses #+# #+# */ -/* Updated: 2024/06/18 16:38:14 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:07:14 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,8 @@ t_stack *ft_sort_two_nbrs(t_stack **stack); t_stack *ft_sort_three_nbrs(t_stack **stack); /* sorting functions if list has until 3 numbers */ -void ft_sort_four_or_more_nbrs(t_stack **stack_a, t_stack **stack_b); +void ft_sort_four_nbrs(t_stack **stack_a, t_stack **stack_b); +void ft_sort_five_or_more_nbr(t_stack **stack_a, t_stack **stack_b); void ft_push_b_all_but_three(t_stack **stack_a, t_stack **stack_b); int ft_lst_get_target(t_stack **stack_a, int b_end_pos, int target_end_pos, int target_pos); diff --git a/program_to_test/src/ft_do_sort.c b/program_to_test/src/ft_do_sort.c index 630cfce..546a387 100644 --- a/program_to_test/src/ft_do_sort.c +++ b/program_to_test/src/ft_do_sort.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/06 18:46:55 by umeneses #+# #+# */ -/* Updated: 2024/06/18 18:12:19 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 15:07:03 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,10 +23,16 @@ void ft_do_sort(t_stack **stack_a, t_stack **stack_b) ft_sort_two_nbrs(stack_a); else if (stack_size == 3) ft_sort_three_nbrs(stack_a); - else + else if (stack_size == 4) + ft_sort_four_nbrs(stack_a, stack_b); + else if (stack_size >= 5) { - ft_sort_four_or_more_nbrs(stack_a, stack_b); + ft_sort_five_or_more_nbr(stack_a, stack_b); } + // else + // { + // ft_sort_five_or_more_nbr(stack_a, stack_b); + // } } } diff --git a/program_to_test/src/ft_swap.c b/program_to_test/src/ft_swap.c index 6e8a439..e13bdef 100644 --- a/program_to_test/src/ft_swap.c +++ b/program_to_test/src/ft_swap.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/13 14:49:58 by umeneses #+# #+# */ -/* Updated: 2024/05/22 15:35:10 by umeneses ### ########.fr */ +/* Updated: 2024/06/19 14:37:01 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,23 @@ void ft_swap(t_stack **stack) { - int temp; + // int temp; - if (*stack == NULL || (*stack)->next == NULL) + // if (NULL == stack || NULL == (*stack)) + // return ; + // temp = (*stack)->nbr; + // (*stack)->nbr = (*stack)->next->nbr; + // (*stack)->next->nbr = temp; + + if (NULL == stack || NULL == (*stack)) return ; - temp = (*stack)->nbr; - (*stack)->nbr = (*stack)->next->nbr; - (*stack)->next->nbr = temp; + (*stack) = (*stack)->next; + (*stack)->prev->prev = (*stack); + (*stack)->prev->next = (*stack)->next; + if ((*stack)->next) + (*stack)->next->prev = (*stack)->prev; + (*stack)->next = (*stack)->prev; + (*stack)->prev = NULL; } void ft_swap_ab(t_stack **stack_a, t_stack **stack_b)