algo is bullshit, everything left to do

This commit is contained in:
hugogogo
2021-07-01 13:48:22 +02:00
parent 95ae6c5c4e
commit 37b1daa814
4 changed files with 30 additions and 23 deletions

Binary file not shown.

Binary file not shown.

BIN
push_swap

Binary file not shown.

View File

@@ -2,22 +2,22 @@
/*
** 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 match(t_stack *a, int n, int *smaller)
{
int smaller;
int position;
int i;
smaller = a->n;
*smaller = a->n;
position = 0;
i = 1;
while (i < n)
while (a->next && i < n)
{
a = a->next;
if (a->n < smaller)
if (a->n < *smaller)
{
smaller = a->n;
*smaller = a->n;
position = i;
}
i++;
@@ -50,28 +50,35 @@ int last_element(t_stack *a)
return (a->n);
}
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 i;
int j;
int last;
int position;
int value;
// last = last_element(*a);
j = 5;
while (--j)
last = last_element(*a);
while ((*a)->n != last)
{
i = match(*a, 4);
nb_to_top(a, solution, i);
if ((*b) && (*a)->n < (*b)->n)
{
ra(a, &solution);
ft_putchar('t');
}
position = match(*a, 4, &value);
if (!(*b) || value > (*b)->n)
push_to_b(a, b, solution, position);
else
{
ft_putchar('v');
pb(b, a, &solution);
}
ra(a, &solution);
}
}
/*