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