algo is bullshit, everything left to do
This commit is contained in:
BIN
builds/algo.o
BIN
builds/algo.o
Binary file not shown.
BIN
builds/print.o
BIN
builds/print.o
Binary file not shown.
53
srcs/algo.c
53
srcs/algo.c
@@ -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);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user