95 lines
1.3 KiB
C
95 lines
1.3 KiB
C
#include "push_swap.h"
|
|
|
|
/*
|
|
** n is the nbr of elements of the list that are competiting
|
|
*/
|
|
int match(t_stack *a, int n)
|
|
{
|
|
int smaller;
|
|
int position;
|
|
int i;
|
|
|
|
smaller = a->n;
|
|
position = 0;
|
|
i = 1;
|
|
while (i < n)
|
|
{
|
|
a = a->next;
|
|
if (a->n < smaller)
|
|
{
|
|
smaller = a->n;
|
|
position = i;
|
|
}
|
|
i++;
|
|
}
|
|
return (position);
|
|
}
|
|
|
|
void nb_to_top(t_stack **a, t_list *solution, int i)
|
|
{
|
|
int n;
|
|
|
|
if (!i)
|
|
return ;
|
|
n = i;
|
|
while (--n)
|
|
ra(a, &solution);
|
|
n = i;
|
|
sa(a, &solution);
|
|
while (--n)
|
|
{
|
|
rra(a, &solution);
|
|
sa(a, &solution);
|
|
}
|
|
}
|
|
|
|
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 last;
|
|
int i;
|
|
int j;
|
|
|
|
// 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);
|
|
pb(b, a, &solution);
|
|
pb(b, a, &solution);
|
|
pb(b, a, &solution);
|
|
pb(b, a, &solution);
|
|
pb(b, a, &solution);
|
|
pa(a, b, &solution);
|
|
sa(a, &solution);
|
|
sb(b, &solution);
|
|
sa(a, &solution);
|
|
rra(a, &solution);
|
|
rrb(b, &solution);
|
|
rrr(a, b, &solution);
|
|
ra(a, &solution);
|
|
rb(b, &solution);
|
|
rr(a, b, &solution);
|
|
*/
|