diff --git a/builds/algo.o b/builds/algo.o index bf62126..00f5526 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..a898837 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 b159a07..9e08696 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o index 34a840f..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 8a07daf..6855ce1 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..a534d1b 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/stop.o b/builds/stop.o index ce7a3f8..22bffca 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..cdfa0da 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/push_swap b/push_swap index 3aff82f..c2ae788 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index efd08bc..f64d96d 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -1,11 +1,51 @@ #include "push_swap.h" +t_list *dup_n_fill(t_stack *a) +{ + t_list *sort; + int *i; + int j; + int *x; + + j = 0; + i = (int *)ft_calloc(3, sizeof(int)); + sort = NULL; + while(a) + { + if(sort){x = sort->content; ft_printf("[%i / ", x[0]);} + + i[0] = a->n; + i[1] = j; + i[2] = 0; + + if(sort){x = sort->content; ft_printf("%i] ", x[0]);} + + ft_lstadd_back(&sort, ft_lstnew(i)); + + x = sort->content; ft_printf("[%i]\n", x[0]); + + a = a->next; + j++; + } + return (sort); +} + void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { (void)b; + (void)a; + (void)solution; + t_list *sort; - pb(b, a, &solution); + sort = dup_n_fill(*a); + int *i; + while(sort) + { + i = sort->content; + ft_printf("%i - %i - %i\n", i[0], i[1], i[2]); + sort = sort->next; + } /* sa(a, &solution); pb(b, a, &solution); diff --git a/srcs/algo_bubble_sort.c b/srcs/algo_bubble_sort.c index c485215..01812fc 100644 --- a/srcs/algo_bubble_sort.c +++ b/srcs/algo_bubble_sort.c @@ -12,7 +12,6 @@ #include "push_swap.h" -/* static int search_smaller(t_stack *stack, int *smaller) { int i; @@ -57,4 +56,3 @@ int bubble_sort(t_stack **a, t_stack **b, t_list *solution) pa(a, b, &solution); return (1); } -*/ diff --git a/srcs/print.c b/srcs/print.c index 8fb063d..5eb0f67 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -23,7 +23,6 @@ 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; @@ -43,16 +42,13 @@ print_test(solution, "fill_solution (beginning)"); 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) { char **part; -print_test(result, "print result "); result = result->next->next; while (result) { diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 602c4d1..18a20ce 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -1,11 +1,6 @@ #include "push_swap.h" -/* -** this function check errors in the arguments -** like, is there arguments, and are they a valid list without equals values -** if there are no arguments it calls the stop function with value 1 to print usage -*/ void is_valid(int ac, char **av) { if (ac < 2) @@ -14,10 +9,6 @@ void is_valid(int ac, char **av) // check more error } -/* -** this function check if there are flags (currently only one flag) : -** -p to print the evolution of the list while the sorting is done -*/ int check_flag(int *ac, char ***av) { if (ft_strcmp((*av)[1], "-p") != 0) @@ -27,9 +18,6 @@ int check_flag(int *ac, char ***av) return (1); } -/* -** create the stack for list a, as a linked list, and fill it with the values given in arguments argv -*/ t_stack *init_stack(int ac, char **av) { t_stack *start; @@ -64,13 +52,10 @@ t_list *launch_algo(t_stack *a, int flag) b = NULL; solution = ft_lstnew(&a); ft_lstadd_back(&solution, ft_lstnew(&b)); -print_test(solution, "launch_algo "); if (flag) fill_solution(solution, ft_strdup("start")); -print_test(solution, "launch_algo (after fill) "); hugo_sort(&a, &b, solution); //bubble_sort(&a, &b, solution); -print_test(solution, "launch_algo (bfr return) "); return (solution); } @@ -92,8 +77,6 @@ int main(int ac, char **av) flag = check_flag(&ac, &av); stack = init_stack(ac, av); result = launch_algo(stack, flag); -print_test(result, "main "); - //sa(&stack, &result); print_result(result, flag); ps_stop(NULL, result, 0); return(0); diff --git a/srcs/rotate.c b/srcs/rotate.c index 68b9c32..8c3370e 100644 --- a/srcs/rotate.c +++ b/srcs/rotate.c @@ -20,14 +20,14 @@ void rotate(t_stack **stack) t_list *ra(t_stack **a, t_list **lst) { rotate(a); - fill_solution(*lst, ft_strdup("ra")); + fill_solution(*lst, "ra"); return (NULL); } t_list *rb(t_stack **b, t_list **lst) { rotate(b); - fill_solution(*lst, ft_strdup("rb")); + fill_solution(*lst, "rb"); return (NULL); } @@ -35,7 +35,7 @@ t_list *rr(t_stack **a, t_stack **b, t_list **lst) { rotate(a); rotate(b); - fill_solution(*lst, ft_strdup("rr")); + fill_solution(*lst, "rr"); return (NULL); } diff --git a/srcs/stop.c b/srcs/stop.c index 625ff4a..a38fd0b 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -1,31 +1,6 @@ #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); -} - void ps_usage(void) { ft_printf("usage :\n"); @@ -94,8 +69,6 @@ void ps_stop(t_stack *stack, t_list *lst, int err) (void)b; */ -print_test(lst, "ps_stop "); - if (err < 0) return ; else if (err > 0) diff --git a/srcs/swap.c b/srcs/swap.c index 2bac144..d2c7afe 100644 --- a/srcs/swap.c +++ b/srcs/swap.c @@ -16,14 +16,14 @@ void swap(t_stack **stack) t_list *sa(t_stack **a, t_list **solution) { swap(a); - fill_solution(*solution, ft_strdup("sa")); + fill_solution(*solution, "sa"); return (NULL); } t_list *sb(t_stack **b, t_list **solution) { swap(b); - fill_solution(*solution, ft_strdup("sb")); + fill_solution(*solution, "sb"); return (NULL); } @@ -31,6 +31,6 @@ t_list *ss(t_stack **a, t_stack **b, t_list **solution) { swap(a); swap(b); - fill_solution(*solution, ft_strdup("sb")); + fill_solution(*solution, "sb"); return (NULL); }