Skip to content

Commit

Permalink
testing new method
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed Jun 19, 2024
1 parent 21884f0 commit dcda709
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
5 changes: 3 additions & 2 deletions program_to_test/headers/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions program_to_test/src/ft_do_sort.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/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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
// }
}
}

Expand Down
22 changes: 16 additions & 6 deletions program_to_test/src/ft_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

#include "push_swap.h"

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)
Expand Down

0 comments on commit dcda709

Please sign in to comment.