diff --git a/README.md b/README.md index 844c4c2..e161e52 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ source des comparaisons ci-dessous : [https://www.youtube.com/watch?v=xoR-1KwQh2 10 4 875 249 56 784 400 Bogo Sort +--- + +autre source de comparaison : [https://www.toptal.com/developers/sorting-algorithms](https://www.toptal.com/developers/sorting-algorithms) + --- ## pour utiliser l'algorithme de tris de ce programme dans votre propre programme, il faut : diff --git a/builds/algo.o b/builds/algo.o index bb713ba..5195668 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index aeea254..4dc54fc 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/compare_pushswap.sh b/compare.sh similarity index 100% rename from compare_pushswap.sh rename to compare.sh diff --git a/push_swap b/push_swap index 3bc14bd..edb7244 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index f0411b6..866cb21 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -1,7 +1,61 @@ #include "push_swap.h" +/* +** the nb compared to i in the while loop is the number +** of elements of the list that are competiting +*/ +int match(t_stack **a) +{ + t_stack *tmp; + int smaller; + int i; + int j; + + tmp = *a; + smaller = tmp->n; + i = 1; + j = 0; + while (i < 4) + { + tmp = tmp->next; + if (tmp->n < smaller) + { + smaller = tmp->n; + j = i; + } + i++; + } + ft_printf("%i [%i]\n", smaller, j); + return (j); +} + +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 hugo_sort(t_stack **a, t_stack **b, t_list *solution) { + int i; + + i = match(a); + nb_to_top(a, solution, i); + (void)b; +} +/* sa(a, &solution); pb(b, a, &solution); pb(b, a, &solution); @@ -18,4 +72,4 @@ 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/push_swap.c b/srcs/push_swap.c index 7203919..70cffa5 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -47,8 +47,8 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag) ft_lstadd_back(&solution, ft_lstnew(b)); if (flag) fill_solution(solution, "start"); - // hugo_sort(a, b, solution); - bubble_sort(a, b, solution); + hugo_sort(a, b, solution); + // bubble_sort(a, b, solution); return (solution); }