algo recursive fonctionne manque le tris des mini listes
This commit is contained in:
70
srcs/algo.c
70
srcs/algo.c
@@ -56,37 +56,74 @@ int find_pivot(t_stack *list, int size)
|
||||
|
||||
int divide_a(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
int list_size;
|
||||
int pivot;
|
||||
int list_size;
|
||||
int pivot;
|
||||
t_stack *first_rotate;
|
||||
|
||||
(void)b;
|
||||
(void)solution;
|
||||
first_rotate = NULL;
|
||||
list_size = sublist_size(*a);
|
||||
pivot = find_pivot(*a, list_size);
|
||||
(*a)->limit = 0;
|
||||
while (list_size-- > 0)
|
||||
{
|
||||
if ((*a)->n >= pivot)
|
||||
{
|
||||
if (!first_rotate)
|
||||
first_rotate = *a;
|
||||
ra(a, &solution);
|
||||
}
|
||||
else
|
||||
pb(b, a, &solution);
|
||||
}
|
||||
mark_step(solution);
|
||||
while (*a != first_rotate)
|
||||
rra(a, &solution);
|
||||
(*a)->limit = 1;
|
||||
(*b)->limit = 1;
|
||||
mark_step(solution, "divide_a");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int divide_b(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)solution;
|
||||
int list_size;
|
||||
int pivot;
|
||||
t_stack *first_rotate;
|
||||
|
||||
first_rotate = NULL;
|
||||
list_size = sublist_size(*b);
|
||||
pivot = find_pivot(*b, list_size);
|
||||
(*b)->limit = 0;
|
||||
while (list_size-- > 0)
|
||||
{
|
||||
if ((*b)->n >= pivot)
|
||||
pa(a, b, &solution);
|
||||
else
|
||||
{
|
||||
if (!first_rotate)
|
||||
first_rotate = *b;
|
||||
rb(b, &solution);
|
||||
}
|
||||
}
|
||||
while (*b != first_rotate)
|
||||
rrb(b, &solution);
|
||||
(*a)->limit = 1;
|
||||
(*b)->limit = 1;
|
||||
mark_step(solution, "divide_b");
|
||||
return (0);
|
||||
}
|
||||
|
||||
void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
(void)a;
|
||||
(void)b;
|
||||
(void)solution;
|
||||
int list_size;
|
||||
|
||||
list_size = sublist_size(*b);
|
||||
(*b)->limit = 0;
|
||||
while (list_size-- > 0)
|
||||
pa(a, b, &solution);
|
||||
(*a)->limit = 1;
|
||||
if (*b)
|
||||
(*b)->limit = 1;
|
||||
mark_step(solution, "send_sublist_to_a");
|
||||
}
|
||||
|
||||
void mini_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
@@ -98,19 +135,18 @@ void mini_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
if (sublist_size(*a) > 5)
|
||||
divide_a(a, b, solution);
|
||||
/*
|
||||
if (sublist_size(*a) > 3)
|
||||
divide_a(a, b, solution);
|
||||
else if (sublist_size(*b) > 3)
|
||||
else if (sublist_size(*b) > 5)
|
||||
{
|
||||
mini_sort(a, b, solution);
|
||||
divide_b(a, b, solution);
|
||||
}
|
||||
else
|
||||
else if (sublist_size(*b) > 0)
|
||||
send_sublist_to_a(a, b, solution);
|
||||
else
|
||||
return ;
|
||||
hugo_sort(a, b, solution);
|
||||
*/
|
||||
}
|
||||
|
||||
// /*
|
||||
|
||||
Reference in New Issue
Block a user