diff --git a/builds/algo.o b/builds/algo.o index 9909ca5..8467c3c 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/print.o b/builds/print.o index af044f1..9c21eb3 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/push_swap b/push_swap index 471f122..9b4919c 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index 57c8934..ccf5a7c 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -2,22 +2,22 @@ /* ** n is the nbr of elements of the list that are competiting +** position start at 0, ie position 3 is the 4th element */ -int match(t_stack *a, int n) +int match(t_stack *a, int n, int *smaller) { - int smaller; int position; int i; - smaller = a->n; + *smaller = a->n; position = 0; i = 1; - while (i < n) + while (a->next && i < n) { a = a->next; - if (a->n < smaller) + if (a->n < *smaller) { - smaller = a->n; + *smaller = a->n; position = i; } i++; @@ -50,28 +50,35 @@ int last_element(t_stack *a) return (a->n); } +void push_to_b(t_stack **a, t_stack **b, t_list *solution, int position) +{ + int i; + + i = position; + while (i--) + ra(a, &solution); + pb(b, a, &solution); + while (++i < position) + rra(a, &solution); +} + +/* +** so far it's bullshit :p +*/ void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { -// int last; - int i; - int j; + int last; + int position; + int value; -// last = last_element(*a); - j = 5; - while (--j) + last = last_element(*a); + while ((*a)->n != last) { - i = match(*a, 4); - nb_to_top(a, solution, i); - if ((*b) && (*a)->n < (*b)->n) - { - ra(a, &solution); - ft_putchar('t'); - } + position = match(*a, 4, &value); + if (!(*b) || value > (*b)->n) + push_to_b(a, b, solution, position); else - { - ft_putchar('v'); - pb(b, a, &solution); - } + ra(a, &solution); } } /*