debut algo tri
This commit is contained in:
@@ -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
|
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 :
|
## pour utiliser l'algorithme de tris de ce programme dans votre propre programme, il faut :
|
||||||
|
|||||||
BIN
builds/algo.o
BIN
builds/algo.o
Binary file not shown.
Binary file not shown.
56
srcs/algo.c
56
srcs/algo.c
@@ -1,7 +1,61 @@
|
|||||||
#include "push_swap.h"
|
#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)
|
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);
|
sa(a, &solution);
|
||||||
pb(b, a, &solution);
|
pb(b, 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);
|
ra(a, &solution);
|
||||||
rb(b, &solution);
|
rb(b, &solution);
|
||||||
rr(a, b, &solution);
|
rr(a, b, &solution);
|
||||||
}
|
*/
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag)
|
|||||||
ft_lstadd_back(&solution, ft_lstnew(b));
|
ft_lstadd_back(&solution, ft_lstnew(b));
|
||||||
if (flag)
|
if (flag)
|
||||||
fill_solution(solution, "start");
|
fill_solution(solution, "start");
|
||||||
// hugo_sort(a, b, solution);
|
hugo_sort(a, b, solution);
|
||||||
bubble_sort(a, b, solution);
|
// bubble_sort(a, b, solution);
|
||||||
return (solution);
|
return (solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user