diff --git a/.main.c.swp b/.main.c.swp new file mode 100644 index 0000000..e3e8cd0 Binary files /dev/null and b/.main.c.swp differ diff --git a/.parsing.c.swp b/.parsing.c.swp new file mode 100644 index 0000000..c6c0258 Binary files /dev/null and b/.parsing.c.swp differ diff --git a/main.c b/main.c index 3d91552..c5cf6e9 100644 --- a/main.c +++ b/main.c @@ -6,35 +6,65 @@ /* By: mteriier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 18:32:35 by mteriier #+# #+# */ -/* Updated: 2025/12/08 20:36:49 by mteriier ### ########.fr */ +/* Updated: 2025/12/09 11:39:55 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" #include +#include -void print_all_stack(t_stack *stack, t_stack *first) +void print_all_stack(t_stack *stack, t_stack *first, char pile) { t_stack *tmp; + int i; tmp = stack; - printf("TAB\n"); + i = 0; + printf("TAB %c : \n", pile); + if (!stack || !first) + return ; while (tmp->next != first) { printf("[%d] ", tmp->value); tmp = tmp->next; + i++; } printf("[%d] \n", tmp->value); } int main(int argc, char **argv) { - t_stack *first; + t_stacks *stacks; + stacks = NULL; if (argc > 1) { - first = parsing(argc, argv); - print_all_stack(first, first); + stacks = init_big_stacks(argc, argv); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + sa(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + pb(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + pa(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + rra(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + pb(stacks); + pb(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + rrb(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); + rrr(stacks); + print_all_stack(stacks->a, stacks->a, 'A'); + print_all_stack(stacks->b, stacks->b, 'B'); } - stack_clear_all(first, first); + stack_clear_all(stacks->a, stacks->a); } diff --git a/parsing.c b/parsing.c index 3c377e2..abf65e6 100644 --- a/parsing.c +++ b/parsing.c @@ -6,17 +6,16 @@ /* By: mteriier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 16:21:05 by mteriier #+# #+# */ -/* Updated: 2025/12/08 20:31:37 by mteriier ### ########.fr */ +/* Updated: 2025/12/09 10:19:17 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" #include -#include t_stack *parsing(int argc, char **argv) { - size_t i; + int i; int stock; t_stack *first; t_stack *new; @@ -39,3 +38,16 @@ t_stack *parsing(int argc, char **argv) } return (first); } + +t_stacks *init_big_stacks(int argc, char **argv) +{ + t_stacks *stacks; + t_stack *a; + + stacks = malloc(sizeof(t_stacks)); + if (!stacks) + return (NULL); + a = parsing(argc, argv); + stacks->a = a; + return (stacks); +} diff --git a/push_swap.h b/push_swap.h index 454c1dd..6f0b3f4 100644 --- a/push_swap.h +++ b/push_swap.h @@ -6,7 +6,7 @@ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */ -/* Updated: 2025/12/08 20:28:41 by mteriier ### ########.fr */ +/* Updated: 2025/12/09 10:17:27 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ @@ -27,23 +27,24 @@ typedef struct s_stacks } t_stacks; /*STACK_FUNCTIONS*/ -void pa(t_stacks *stacks); -void pb(t_stacks *stacks); -void rra(t_stacks *stacks); -void rrb(t_stacks *stacks); -void rrr(t_stacks *stacks); -void ra(t_stacks *stacks); -void rb(t_stacks *stacks); -void rr(t_stacks *stacks); -void sa(t_stacks *stacks); -void sb(t_stacks *stacks); -void ss(t_stacks *stacks); +void pa(t_stacks *stacks); +void pb(t_stacks *stacks); +void rra(t_stacks *stacks); +void rrb(t_stacks *stacks); +void rrr(t_stacks *stacks); +void ra(t_stacks *stacks); +void rb(t_stacks *stacks); +void rr(t_stacks *stacks); +void sa(t_stacks *stacks); +void sb(t_stacks *stacks); +void ss(t_stacks *stacks); /*FUNCTION UTILS*/ -t_stack *new_stack(int value); -void stack_add_back(t_stack **stack, t_stack *new); -void stack_add_front(t_stack **stack, t_stack *new); -void stack_clear_all(t_stack *stack, t_stack *first); -t_stack *parsing(int argc, char **argv); -int ft_atoi(const char *nptr); +t_stack *new_stack(int value); +void stack_add_back(t_stack **stack, t_stack *new); +void stack_add_front(t_stack **stack, t_stack *new); +void stack_clear_all(t_stack *stack, t_stack *first); +t_stack *parsing(int argc, char **argv); +t_stacks *init_big_stacks(int argc, char **argv); +int ft_atoi(const char *nptr); #endif diff --git a/stack_utils/.push.c.swp b/stack_utils/.push.c.swp new file mode 100644 index 0000000..00fbb73 Binary files /dev/null and b/stack_utils/.push.c.swp differ diff --git a/stack_utils/.stack_add.c.swp b/stack_utils/.stack_add.c.swp new file mode 100644 index 0000000..502b12d Binary files /dev/null and b/stack_utils/.stack_add.c.swp differ diff --git a/stack_utils/push.c b/stack_utils/push.c index ef35775..126ff89 100644 --- a/stack_utils/push.c +++ b/stack_utils/push.c @@ -6,28 +6,48 @@ /* By: mteriier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */ -/* Updated: 2025/12/08 19:37:01 by mteriier ### ########.fr */ +/* Updated: 2025/12/09 11:36:36 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include "../push_swap.h" +#include void pa(t_stacks *stacks) { - t_stack *a; + t_stack *b_push; if (!stacks || !stacks->b) return ; - a = stacks->a; - a->value = stacks->b->value; + b_push = stacks->b; + if (stacks->b->next == stacks->b) + stacks->b = NULL; + else + { + stacks->b->next->previous = stacks->b->previous; + stacks->b->previous->next = stacks->b->next; + stacks->b = stacks->b->next; + } + stack_add_front(&(stacks->a), b_push); + } +#include + void pb(t_stacks *stacks) { - t_stack *b; + t_stack *a_push; if (!stacks || !stacks->a) return ; - b = stacks->b; - b->value = stacks->a->value; + a_push = stacks->a; + if (stacks->a->next == stacks->a) + stacks->a = NULL; + else + { + stacks->a->next->previous = stacks->a->previous; + stacks->a->previous->next = stacks->a->next; + stacks->a = stacks->a->next; + } + stack_add_front(&(stacks->b), a_push); } diff --git a/stack_utils/stack_add.c b/stack_utils/stack_add.c index d7cd0c6..761143a 100644 --- a/stack_utils/stack_add.c +++ b/stack_utils/stack_add.c @@ -6,7 +6,7 @@ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */ -/* Updated: 2025/12/08 20:33:58 by mteriier ### ########.fr */ +/* Updated: 2025/12/09 08:51:33 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,6 @@ t_stack *new_stack(int value) return (new); } -#include - void stack_add_back(t_stack **stack, t_stack *new) { if (!stack || !new)