debut algo tri

This commit is contained in:
hugogogo
2021-06-29 23:49:06 +02:00
parent f081f15f58
commit 023c7d29f6
7 changed files with 61 additions and 3 deletions

View File

@@ -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 :

Binary file not shown.

Binary file not shown.

BIN
push_swap

Binary file not shown.

View File

@@ -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);
}
*/

View File

@@ -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);
}