mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
Compare commits
1 Commits
e2cbea4df9
...
parsing
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67d7509faf |
BIN
.main.c.swp
Normal file
BIN
.main.c.swp
Normal file
Binary file not shown.
BIN
.parsing.c.swp
Normal file
BIN
.parsing.c.swp
Normal file
Binary file not shown.
44
main.c
44
main.c
@@ -6,35 +6,65 @@
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
18
parsing.c
18
parsing.c
@@ -6,17 +6,16 @@
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
37
push_swap.h
37
push_swap.h
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
||||
BIN
stack_utils/.push.c.swp
Normal file
BIN
stack_utils/.push.c.swp
Normal file
Binary file not shown.
BIN
stack_utils/.stack_add.c.swp
Normal file
BIN
stack_utils/.stack_add.c.swp
Normal file
Binary file not shown.
@@ -6,28 +6,48 @@
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
|
||||
void stack_add_back(t_stack **stack, t_stack *new)
|
||||
{
|
||||
if (!stack || !new)
|
||||
|
||||
Reference in New Issue
Block a user