diff --git a/builds/algo.o b/builds/algo.o deleted file mode 100644 index 8467c3c..0000000 Binary files a/builds/algo.o and /dev/null differ diff --git a/builds/algo_bubble_sort.o b/builds/algo_bubble_sort.o deleted file mode 100644 index a481d60..0000000 Binary files a/builds/algo_bubble_sort.o and /dev/null differ diff --git a/builds/print.o b/builds/print.o deleted file mode 100644 index 9c21eb3..0000000 Binary files a/builds/print.o and /dev/null differ diff --git a/builds/push.o b/builds/push.o deleted file mode 100644 index f76518b..0000000 Binary files a/builds/push.o and /dev/null differ diff --git a/builds/push_swap.o b/builds/push_swap.o deleted file mode 100644 index 0d35bb2..0000000 Binary files a/builds/push_swap.o and /dev/null differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o deleted file mode 100644 index 0d77b92..0000000 Binary files a/builds/reverse_rotate.o and /dev/null differ diff --git a/builds/rotate.o b/builds/rotate.o deleted file mode 100644 index d273614..0000000 Binary files a/builds/rotate.o and /dev/null differ diff --git a/builds/stop.o b/builds/stop.o deleted file mode 100644 index b9fe97b..0000000 Binary files a/builds/stop.o and /dev/null differ diff --git a/builds/swap.o b/builds/swap.o deleted file mode 100644 index 2ae8f0d..0000000 Binary files a/builds/swap.o and /dev/null differ diff --git a/libft b/libft index 5634df6..4aa6356 120000 --- a/libft +++ b/libft @@ -1 +1 @@ -../libft \ No newline at end of file +../../libft \ No newline at end of file diff --git a/push_swap b/push_swap deleted file mode 100755 index 9b4919c..0000000 Binary files a/push_swap and /dev/null differ diff --git a/srcs/algo.c b/srcs/algo.c index ccf5a7c..1191580 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -1,48 +1,5 @@ #include "push_swap.h" -/* -** 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 *smaller) -{ - int position; - int i; - - *smaller = a->n; - position = 0; - i = 1; - while (a->next && i < n) - { - a = a->next; - if (a->n < *smaller) - { - *smaller = a->n; - position = i; - } - i++; - } - return (position); -} - -void nb_to_top(t_stack **a, t_list *solution, int i) -{ - int n; - - if (!i) - return ; - n = i; - while (--n) - ra(a, &solution); - n = i; - sa(a, &solution); - while (--n) - { - rra(a, &solution); - sa(a, &solution); - } -} - int last_element(t_stack *a) { while (a->next) @@ -50,37 +7,104 @@ int last_element(t_stack *a) return (a->n); } -void push_to_b(t_stack **a, t_stack **b, t_list *solution, int position) +void recursive(t_stack **a, t_stack **b, t_list *solution, int last) { - 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 position; - int value; - - last = last_element(*a); - while ((*a)->n != last) + if (sublist_size(last, *a) > 5) + pivot_a_to_b(a, b, solution, last); + else { - position = match(*a, 4, &value); - if (!(*b) || value > (*b)->n) - push_to_b(a, b, solution, position); + sort_sublist_a(a, b, solution, last); + if (sublist_size(last, *b) < 5) + send_sublist_to_a(a, b, solution, last); else - ra(a, &solution); + pivot_b_to_a(a, b, solution, last); } } + +void hugo_sort(t_stack **a, t_stack **b, t_list *solution) +{ + (void)solution; + (void)b; + int last; + + last = last_element(*a); + recursive(*a, *b, solution, last); +} + +// /* +// ** 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 *smaller) +// { +// int position; +// int i; +// +// *smaller = a->n; +// position = 0; +// i = 1; +// while (a->next && i < n) +// { +// a = a->next; +// if (a->n < *smaller) +// { +// *smaller = a->n; +// position = i; +// } +// i++; +// } +// return (position); +// } +// +// void nb_to_top(t_stack **a, t_list *solution, int i) +// { +// int n; +// +// if (!i) +// return ; +// n = i; +// while (--n) +// ra(a, &solution); +// n = i; +// sa(a, &solution); +// while (--n) +// { +// rra(a, &solution); +// sa(a, &solution); +// } +// } +// +// 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 position; +// int value; +// +// last = last_element(*a); +// while ((*a)->n != last) +// { +// position = match(*a, 4, &value); +// if (!(*b) || value > (*b)->n) +// push_to_b(a, b, solution, position); +// else +// ra(a, &solution); +// } +// } /* sa(a, &solution); pb(b, a, &solution); diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 70cffa5..904bf78 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -48,7 +48,7 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag) if (flag) fill_solution(solution, "start"); hugo_sort(a, b, solution); - // bubble_sort(a, b, solution); + //bubble_sort(a, b, solution); return (solution); }