diff --git a/builds/algo.o b/builds/algo.o index 69b77a3..fa70d6e 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/pushswap.o b/builds/pushswap.o index 4817c02..0a5be1c 100644 Binary files a/builds/pushswap.o and b/builds/pushswap.o differ diff --git a/builds/swap.o b/builds/swap.o index dab233a..ef5b28d 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/pushswap b/pushswap index 7b6974c..10c091c 100755 Binary files a/pushswap and b/pushswap differ diff --git a/srcs/algo.c b/srcs/algo.c index ba2468b..a935aa5 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -6,61 +6,38 @@ ** then it launch the action (swap, push, rotate) */ -void action(t_list *pack, void (*sp)(t_list *pack)) +void action(t_stack *stack_a, t_stack *stack_b, t_list *solution, int flag, + void (*sp)(t_list *pack)) { - t_stack *stack_a; - t_stack *stack_b; - t_list **solution; - int flag; - - stack_a = pack->content; - stack_b = pack->next->content; - solution = pack->next->next->content; - flag = *(int *)(pack->next->next->next->content); // this is a really ugly line :p it's because lst->content is a void*, but we need an int if (!flag) // if flag == 0, don't print anything return ; - if (!*solution) // to print only at first call + 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'); } -t_list *do_pack(t_stack *stack_a, int flag) -{ - t_stack *stack_b; - t_list *pack; - - if(!(stack_b = ft_calloc(1, sizeof(t_stack)))) - ps_stop(stack_a, stack_b, NULL, 2); - pack = ft_lstnew(stack_a); - ft_lstadd_back(&pack, ft_lstnew(stack_b)); - ft_lstadd_back(&pack, ft_lstnew(NULL)); - ft_lstadd_back(&pack, ft_lstnew(&flag)); - return (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, int flag) +t_list *sort_algo(t_stack *a, int f) { - t_list *pack; + t_stack *b; + t_list *solution; - pack = do_pack(stack, flag); - action(pack, sa); - action(pack, sa); + 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); diff --git a/srcs/pushswap.c b/srcs/pushswap.c index 8eed16f..eb16f9f 100644 --- a/srcs/pushswap.c +++ b/srcs/pushswap.c @@ -45,7 +45,7 @@ int main(int ac, char **av) flag = check_flag(&ac, &av); //check for flag, like print stack = init_stack(ac, av); // create the list from av[] result = sort_algo(stack, flag); - print_result(result); +// print_result(result); ps_stop(stack, NULL, result, 0); return(0); } diff --git a/srcs/swap.c b/srcs/swap.c index dded21e..5cb01e3 100644 --- a/srcs/swap.c +++ b/srcs/swap.c @@ -4,16 +4,16 @@ void sa(t_list *pack) { t_stack *stack_a; -// t_list **solution; + t_list **solution; int tmp; stack_a = pack->content; -// solution = pack->next->next->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; -// ft_lstadd_back(solution, ft_lstnew(ft_strdup("sa"))); + ft_lstadd_back(solution, ft_lstnew(ft_strdup("sa"))); }