diff --git a/builds/algo.o b/builds/algo.o index 0999852..106a6d4 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/pushswap.o b/builds/pushswap.o index 77f8165..e4811c0 100644 Binary files a/builds/pushswap.o and b/builds/pushswap.o differ diff --git a/builds/stop.o b/builds/stop.o index 812c4e8..45d914f 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/pushswap b/pushswap index 7b15bce..97457b7 100755 Binary files a/pushswap and b/pushswap differ diff --git a/srcs/algo.c b/srcs/algo.c index 8bd20a5..77a69c7 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -1,12 +1,78 @@ - #include "pushswap.h" -t_list *sort_algo(t_stack *stack) +void sa(t_list *pack) { - (void)stack; - t_list *lst; + t_stack *stack_a; + t_list **solution; + int tmp; - lst = ft_lstnew(ft_strdup("solution")); - return (lst); + stack_a = pack->content; + solution = pack->next->next->content; + if (!stack_a->next) + return ; + tmp = stack_a->n; + stack_a->n = stack_a->next->n; + stack_a->next->n = tmp; + (*solution)->content = ft_strdup("sa"); + ft_lstadd_back(solution, ft_lstnew(NULL)); +} + +/* +** this function +*/ + +void action(t_list *pack, void (*sp)(t_list *pack)) +{ + t_stack *stack_a; + t_stack *stack_b; + t_list **solution; + + stack_a = pack->content; + stack_b = pack->next->content; + solution = pack->next->next->content; + print_stack(stack_a); + print_stack(stack_b); + ft_printf("%s\n", (*solution)->content); + sp(pack); +} + + +/* +** this function create the structures "solution" and "stack_b" +** and put their together with "stack_a" in "pack" to facilitate +** the calls of functions. so pack contains : +** - stack_a +** - stack_b +** - solution +** then it calls the algorithm +*/ + +t_list *sort_algo(t_stack *stack_a) +{ + t_stack *stack_b; + t_list *solution; + t_list *pack; + + solution = ft_lstnew(NULL); + if(!(stack_b = ft_calloc(1, sizeof(t_stack)))) + ps_stop(stack_a, stack_b, solution, 2); + pack = ft_lstnew(stack_a); + ft_lstadd_back(&pack, ft_lstnew(stack_b)); + ft_lstadd_back(&pack, ft_lstnew(&solution)); + action(pack, sa); + print_stack(stack_a); + print_stack(stack_b); +// 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); + return (solution); } diff --git a/srcs/pushswap.c b/srcs/pushswap.c index 5ec7549..2c37871 100644 --- a/srcs/pushswap.c +++ b/srcs/pushswap.c @@ -33,9 +33,8 @@ int main(int ac, char **av) is_valid(ac, av); // check if usage and list are correct stack = init_stack(ac, av); // create the list from av[] - print_stack(stack); result = sort_algo(stack); - ft_printf("%s\n", result->content); + ft_printf("\n%s\n", result->content); ps_stop(stack, NULL, result, 0); return(0); } diff --git a/srcs/stop.c b/srcs/stop.c index 6f00162..570b95a 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -23,6 +23,9 @@ void ps_stop(t_stack *stack_a, t_stack *stack_b, t_list *solution, int err) ft_lstclear((t_list **)&stack_b, NULL); if (solution) ft_lstclear(&solution, free); - ps_error(err); + if (err < 0) + return ; + else if (err > 0) + ps_error(err); exit(0); }