126 lines
2.2 KiB
C
126 lines
2.2 KiB
C
#include "push_swap.h"
|
|
|
|
int last_element(t_stack *a)
|
|
{
|
|
while (a->next)
|
|
a = a->next;
|
|
return (a->n);
|
|
}
|
|
|
|
void recursive(t_stack **a, t_stack **b, t_list *solution, int last)
|
|
{
|
|
if (sublist_size(last, *a) > 5)
|
|
pivot_a_to_b(a, b, solution, last);
|
|
else
|
|
{
|
|
sort_sublist_a(a, b, solution, last);
|
|
if (sublist_size(last, *b) < 5)
|
|
send_sublist_to_a(a, b, solution, last);
|
|
else
|
|
pivot_b_to_a(a, b, solution, last);
|
|
}
|
|
}
|
|
|
|
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
|
{
|
|
(void)solution;
|
|
(void)b;
|
|
int last;
|
|
|
|
last = last_element(*a);
|
|
recursive(*a, *b, solution, last);
|
|
}
|
|
|
|
// /*
|
|
// ** 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 *smaller)
|
|
// {
|
|
// int position;
|
|
// int i;
|
|
//
|
|
// *smaller = a->n;
|
|
// position = 0;
|
|
// i = 1;
|
|
// while (a->next && 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);
|
|
// }
|
|
// }
|
|
//
|
|
// 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 position;
|
|
// int value;
|
|
//
|
|
// last = last_element(*a);
|
|
// while ((*a)->n != last)
|
|
// {
|
|
// position = match(*a, 4, &value);
|
|
// if (!(*b) || value > (*b)->n)
|
|
// push_to_b(a, b, solution, position);
|
|
// else
|
|
// ra(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);
|
|
*/
|