les stacks se sauvegardent dans solution

This commit is contained in:
hugogogo
2021-06-14 12:32:06 +02:00
parent ef7ffdb4dc
commit 7a0f44c676
8 changed files with 21 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -33,7 +33,7 @@ t_list *sort_algo(t_stack *stack);
/*
** print.c
*/
void fill_solution(t_stack **a, t_stack **b, t_list **lst, char *c);
void fill_solution(t_stack *a, t_stack *b, t_list **lst, char *c);
void print_stack(t_stack *stack, char c);
void print_result(t_list *lst);

BIN
pushswap

Binary file not shown.

View File

@@ -1,11 +1,26 @@
#include "pushswap.h"
void fill_solution(t_stack **a, t_stack **b, t_list **solution, char *sp)
void fill_solution(t_stack *a, t_stack *b, t_list **solution, char *sp)
{
(void)a;
char *stack;
(void)b;
ft_lstadd_back(solution, ft_lstnew(sp));
stack = ft_strdup(sp);
stack = ft_strjoinfree(stack, ft_strdup(" a"));
while(a)
{
stack = ft_strjoinfree(stack, ft_strdup(" "));
stack = ft_strjoinfree(stack, ft_itoa(a->n));
a = a->next;
}
while(b)
{
stack = ft_strjoinfree(stack, ft_strdup(" "));
stack = ft_strjoinfree(stack, ft_itoa(a->n));
b = b->next;
}
ft_lstadd_back(solution, ft_lstnew(stack));
}
void print_stack(t_stack *stack, char c)

View File

@@ -1,5 +1,6 @@
#include "pushswap.h"
#include <fcntl.h>
void is_valid(int ac, char **av)
{

View File

@@ -12,7 +12,7 @@ t_list *sa(t_stack **stack, t_list **solution)
tmp = a->n;
a->n = a->next->n;
a->next->n = tmp;
fill_solution(stack, NULL, solution, ft_strdup("sa"));
fill_solution(*stack, NULL, solution, ft_strdup("sa"));
return (NULL);
}