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
|
** 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user