ca remarche et c compatible avec luke
This commit is contained in:
50
srcs/algo.c
50
srcs/algo.c
@@ -1,34 +1,20 @@
|
||||
|
||||
#include "pushswap.h"
|
||||
|
||||
/*
|
||||
** this function is only used to print the stack and the action
|
||||
** then it launch the action (swap, push, rotate)
|
||||
*/
|
||||
|
||||
void action(t_stack *stack_a, t_stack *stack_b, t_list *solution, int flag,
|
||||
void (*sp)(t_list *pack))
|
||||
void hugo_sort(t_stack **a, t_list **solution)
|
||||
{
|
||||
if (!flag) // if flag == 0, don't print anything
|
||||
return ;
|
||||
if (!(*solution)) // to print only at first call
|
||||
{
|
||||
print_stack(stack_a, 'a');
|
||||
print_stack(stack_b, 'b');
|
||||
}
|
||||
sp(pack); // the action to execute
|
||||
ft_putchar('t');
|
||||
ft_printf("%s\n", (*solution)->content);
|
||||
ft_putchar('u');
|
||||
print_stack(stack_a, 'a');
|
||||
print_stack(stack_b, 'b');
|
||||
sa(a, solution);
|
||||
sa(a, solution);
|
||||
sa(a, solution);
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
** this function creates the stack b and the list solution
|
||||
** then it calls the sorting algorithm
|
||||
** then it frees everything that needs to be freed
|
||||
*/
|
||||
|
||||
t_list *sort_algo(t_stack *a, int f)
|
||||
t_list *sort_algo(t_stack *a)
|
||||
{
|
||||
t_stack *b;
|
||||
t_list *solution;
|
||||
@@ -36,21 +22,7 @@ t_list *sort_algo(t_stack *a, int f)
|
||||
solution = NULL;
|
||||
if(!(b = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(a, b, NULL, 2);
|
||||
action(a, b, solution, f, sa);
|
||||
action(a, b, solution, f, sa);
|
||||
// sa(stack_a, stack_b, &solution);
|
||||
// sb(stack_a, stack_b, &solution);
|
||||
// ss(stack_a, stack_b, &solution);
|
||||
// pa(stack_a, stack_b, &solution);
|
||||
// pb(stack_a, stack_b, &solution);
|
||||
// ra(stack_a, stack_b, &solution);
|
||||
// rb(stack_a, stack_b, &solution);
|
||||
// rr(stack_a, stack_b, &solution);
|
||||
// rra(stack_a, stack_b, &solution);
|
||||
// rrb(stack_a, stack_b, &solution);
|
||||
// rrr(stack_a, stack_b, &solution);
|
||||
if (flag)
|
||||
ft_putchar('\n');
|
||||
ps_stop(NULL, pack->next->content, NULL, -1); // pack->next->content is stack_b
|
||||
return (pack->next->next->content); // pack->next->next->content is t_list *solution
|
||||
hugo_sort(&a, &solution);
|
||||
ps_stop(NULL, b, NULL, -1);
|
||||
return (solution);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user