fonction fillsolution remplis les lignes dans le bon sens

This commit is contained in:
hugogogo
2021-07-01 12:35:28 +02:00
parent c6edab3883
commit 95ae6c5c4e
14 changed files with 64 additions and 36 deletions

View File

@@ -1,32 +1,28 @@
#include "push_swap.h"
/*
** the nb compared to i in the while loop is the number
** of elements of the list that are competiting
** n is the nbr of elements of the list that are competiting
*/
int match(t_stack **a)
int match(t_stack *a, int n)
{
t_stack *tmp;
int smaller;
int position;
int i;
int j;
tmp = *a;
smaller = tmp->n;
smaller = a->n;
position = 0;
i = 1;
j = 0;
while (i < 4)
while (i < n)
{
tmp = tmp->next;
if (tmp->n < smaller)
a = a->next;
if (a->n < smaller)
{
smaller = tmp->n;
j = i;
smaller = a->n;
position = i;
}
i++;
}
ft_printf("%i [%i]\n", smaller, j);
return (j);
return (position);
}
void nb_to_top(t_stack **a, t_list *solution, int i)
@@ -47,13 +43,36 @@ void nb_to_top(t_stack **a, t_list *solution, int i)
}
}
int last_element(t_stack *a)
{
while (a->next)
a = a->next;
return (a->n);
}
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
{
int i;
// int last;
int i;
int j;
i = match(a);
nb_to_top(a, solution, i);
(void)b;
// last = last_element(*a);
j = 5;
while (--j)
{
i = match(*a, 4);
nb_to_top(a, solution, i);
if ((*b) && (*a)->n < (*b)->n)
{
ra(a, &solution);
ft_putchar('t');
}
else
{
ft_putchar('v');
pb(b, a, &solution);
}
}
}
/*
sa(a, &solution);