diff --git a/builds/algo.o b/builds/algo.o index d47273b..15f25ba 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/algo_bubble_sort.o b/builds/algo_bubble_sort.o index 0c034c7..2a7786b 100644 Binary files a/builds/algo_bubble_sort.o and b/builds/algo_bubble_sort.o differ diff --git a/builds/print.o b/builds/print.o index 48acbb9..5819b1b 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o index e1eb539..0e77e67 100644 Binary files a/builds/push.o and b/builds/push.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index f3adcdd..09ad998 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o index 3022223..b3f6f9e 100644 Binary files a/builds/reverse_rotate.o and b/builds/reverse_rotate.o differ diff --git a/builds/rotate.o b/builds/rotate.o index 0105699..b73699f 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/stop.o b/builds/stop.o index 5f981e3..4088fad 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/builds/swap.o b/builds/swap.o index 8df6c67..7673fb8 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/includes/push_swap.h b/includes/push_swap.h index edadc27..619c1a1 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -40,7 +40,8 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *lst); /* ** print.c */ -void fill_solution(t_list *lst, char *c); +void print_test(t_list *lst, char *s); +void fill_solution(t_list *lst, char *s); void print_result(t_list *lst, int i); /* diff --git a/push_swap b/push_swap index a23af83..eba674a 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index 8d251f9..efd08bc 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -5,6 +5,8 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { (void)b; + pb(b, a, &solution); + /* sa(a, &solution); pb(b, a, &solution); pb(b, a, &solution); @@ -21,5 +23,6 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution) ra(a, &solution); rb(b, &solution); rr(a, b, &solution); + */ } diff --git a/srcs/print.c b/srcs/print.c index a8df9ab..608b4b9 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -1,10 +1,35 @@ #include "push_swap.h" +void print_test(t_list *lst, char *s) +{ + t_stack **tmpa; + t_stack **tmpb; + t_stack *a; + t_stack *b; + + tmpa = lst->content; + tmpb = lst->next->content; + a = *tmpa; + b = *tmpb; + ft_printf("%s -> a: %12i . %12i . ", s, tmpa, a); + if (a) + ft_printf("%12i", a->n); + else + ft_printf(" NULL"); + ft_printf(" | b: %12i . %12i . ", tmpb, b); + if (b) + ft_printf("%12i \n", b->n); + else + ft_printf(" NULL\n"); + + //ft_printf("%s -> a: %i , %i , %i / b: %i , %i, %i \n", s, tmpa, a, a->n, tmpb, b, b->n); +} + /* ** this function is called at each action (pushes, swapes, rotates) ** pointers to the stacks a and b are stored into two first element of list solution (because both lists a and b are not available from every functions, like sa() doesn't receive b in argument) -** the function access the list to fill a new element with three things : +** the function access the list after the two first elements to fill a new element with three things : ** - the name of the action (sa, sp, rra, etc) ** - the stack a ** - the stack b @@ -23,13 +48,14 @@ void fill_solution(t_list *solution, char *sp) t_stack *b; char *stack; + print_test(solution, "fill_solution (beginning)"); tmp1 = solution->content; tmp2 = solution->next->content; a = *tmp1; b = *tmp2; stack = ft_strdup(sp); stack = ft_strjoinfree(stack, ft_strdup("!a:")); - while(a) + while(a != NULL) { stack = ft_strjoinfree(stack, ft_strdup(" ")); stack = ft_strjoinfree(stack, ft_itoa(a->n)); @@ -42,7 +68,9 @@ void fill_solution(t_list *solution, char *sp) stack = ft_strjoinfree(stack, ft_itoa(b->n)); b = b->next; } + print_test(solution, "fill_solu. (bfr add_back)"); ft_lstadd_back(&solution, ft_lstnew(stack)); + print_test(solution, "fill_solu. (aft add_back)"); } void print_result(t_list *result, int flag) diff --git a/srcs/push.c b/srcs/push.c index ad60a77..e6461cb 100644 --- a/srcs/push.c +++ b/srcs/push.c @@ -6,6 +6,8 @@ void push(t_stack **dst, t_stack **src) t_stack *tmp1; t_stack *tmp2; + if (!((*src)->next)) + return ; tmp1 = *src; tmp2 = *dst; *src = (*src)->next; diff --git a/srcs/push_swap.c b/srcs/push_swap.c index da46b2f..be3fe5f 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -62,10 +62,11 @@ t_list *launch_algo(t_stack *a) t_list *solution; b = NULL; - solution = NULL; - ft_lstadd_back(&solution, ft_lstnew(&a)); + solution = ft_lstnew(&a); ft_lstadd_back(&solution, ft_lstnew(&b)); + print_test(solution, "launch_algo "); fill_solution(solution, ft_strdup("start")); + print_test(solution, "launch_algo (after fill) "); hugo_sort(&a, &b, solution); //bubble_sort(&a, &b, solution); return (solution); @@ -89,6 +90,9 @@ int main(int ac, char **av) flag = check_flag(&ac, &av); stack = init_stack(ac, av); result = launch_algo(stack); + print_test(result, "main "); + //sa(&stack, &result); + print_result(result, flag); ps_stop(NULL, result, 0); return(0); diff --git a/srcs/stop.c b/srcs/stop.c index b94a4f4..141d032 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -18,28 +18,62 @@ void ps_error(int err) void ps_stop(t_stack *stack, t_list *lst, int err) { + /* t_stack **a; t_stack **b; t_list *solution; - (void)stack; - (void)a; - (void)b; - (void)solution; - (void)lst; if (stack) ft_lstclear((t_list **)&stack, NULL); if (lst) { a = lst->content; b = lst->next->content; - solution = lst->next->next; ft_lstclear((t_list **)a, NULL); ft_lstclear((t_list **)b, NULL); - ft_lstclear(&solution, free); + ft_lstclear(&lst, free); } + (void)solution; + */ + +/* + t_list *tmp; + t_stack **aa; + t_stack **bb; + t_stack *a; + t_stack *b; + + aa = lst->content; + a = *aa; + bb = lst->next->content; + b = *bb; +// ft_putnbrendl(a->n); +// ft_putnbrendl(b->n); + + tmp = lst; + lst = lst->next; + free(tmp); + + tmp = lst; + lst = lst->next; + free(tmp); + + while (lst) + { + tmp = lst->next; + free(lst->content); + free(lst); + lst = tmp; + } + (void)a; + (void)b; +*/ + + print_test(lst, "ps_stop "); if (err < 0) return ; else if (err > 0) ps_error(err); + (void)stack; + (void)lst; }