bug dans sort qui semble marcher mais ne passe pas le checker par contre parsing arguments fonctionne dans les deux modes

This commit is contained in:
hugogogo
2021-09-26 10:56:44 +02:00
parent 115c03b8ca
commit 8ded5f93cf
7 changed files with 215 additions and 21 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Executable
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1
Submodule push_swap_tester added at 0fd5c414c6
+181 -5
View File
@@ -126,26 +126,202 @@ void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution)
mark_step(solution, "send_sublist_to_a");
}
/*
int find_smallest(t_stack *list, int size)
{
t_stack *head;
int smallest;
int position;
smallest = list->n;
head = list;
while (--size > 0)
{
head = head->next;
if (head->n < smallest)
smallest = head->n;
}
position = 0;
while (list->n != smallest)
{
position++;
list = list->next;
}
return (position);
}
void mini_sort(t_stack **a, t_stack **b, t_list *solution)
{
(void)a;
(void)b;
(void)solution;
int list_size;
int next;
int temp;
list_size = sublist_size(*a);
if(list_size == 1)
return ;
(*a)->limit = 0;
while (--list_size > 0)
{
next = find_smallest(*a, list_size + 1);
temp = next;
while (next-- > 0)
ra(a, &solution);
pb(b, a, &solution);
while (temp-- > 0)
rra(a, &solution);
}
list_size = sublist_size(*b);
while (list_size-- > 0)
pa(a, b, &solution);
(*a)->limit = 1;
mark_step(solution, "mini_sort");
}
*/
/*
void check_front(t_stack *list, int i, int *position, int *smallest)
{
int j;
j = 1;
while (list->next && j++ < i)
list = list->next;
if (list->n < *smallest)
{
*smallest = list->n;
*position = i;
}
}
void check_back(t_stack *list, int i, int *position, int *smallest)
{
t_stack *head;
int j;
head = list;
j = 1;
while (head != NULL)
{
head = head->next;
j++;
}
head = list;
j -= i;
while (head->next && j-- >= 0)
head = head->next;
if (head->n < *smallest)
{
*smallest = head->n;
*position = i;
}
}
int find_smallest(t_stack *list, int size)
{
int i;
int front;
int back;
int smallest;
int position;
smallest = list->n;
i = 1;
position = 1;
front = sublist_size(list);
back = size - front;
while (++i <= front)
check_front(list, i, &position, &smallest);
i = 0;
while (--i >= back)
check_back(list, i, &position, &smallest);
ft_printf(" / smallest:%i ", smallest);
return (position);
}
*/
void mark_sublist(t_stack *list)
{
while (list && list->limit != 1)
{
if (list->limit == 2)
list->limit = 0;
else if (list->limit == 0)
list->limit = 2;
list = list->next;
}
}
int find_smallest(t_stack *list)
{
int i;
int smallest;
int position;
smallest = list->n;
position = 1;
i = 0;
while (list)
{
i++;
if (list->limit == 2 && list->n < smallest)
{
smallest = list->n;
position = i;
}
list = list->next;
}
if (i - position + 1 < position)
position = position - i - 1;
return (position);
}
void mini_sort(t_stack **a, t_stack **b, t_list *solution)
{
int list_size;
int next;
int i;
list_size = sublist_size(*a);
if(list_size == 1)
return ;
(*a)->limit = 0;
mark_sublist(*a);
t_stack *test;test = *a;while (test){ft_printf("%i(%i)-", test->n, test->limit);test = test->next;}
while (--list_size >= 0)
{
i = 0;
next = find_smallest(*a);
ft_printf(" / %i", next);
if (next > 0)
while (++i < next)
ra(a, &solution);
else if (next < 0)
while (i-- > next)
rra(a, &solution);
pb(b, a, &solution);
}
list_size = sublist_size(*b);
while (list_size-- > 0)
pa(a, b, &solution);
mark_sublist(*a);
(*a)->limit = 1;
mark_step(solution, "mini_sort");
}
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
{
if (sublist_size(*a) > 5)
divide_a(a, b, solution);
else if (sublist_size(*b) > 5)
else
{
mini_sort(a, b, solution);
if (sublist_size(*b) > 5)
divide_b(a, b, solution);
}
else if (sublist_size(*b) > 0)
send_sublist_to_a(a, b, solution);
else
return ;
}
hugo_sort(a, b, solution);
}
+28 -11
View File
@@ -25,23 +25,40 @@ int check_flag(int *ac, char ***av)
return (0);
}
t_stack *fill_stack(t_stack *list, char *nb)
{
t_stack *new;
new = ft_calloc(1, sizeof(t_stack));
if (!new)
ps_stop(NULL, NULL, 2);
new->n = ft_atoi(nb);
new->limit = 0;
new->next = list;
list = new;
return (list);
}
t_stack *init_stack(int ac, char **av)
{
t_stack *start;
t_stack *tmp;
char **split;
t_stack *list;
int i;
tmp = NULL;
list = NULL;
if (ac > 2)
while (--ac)
list = fill_stack(list, av[ac]);
else if (ac == 2)
{
start = ft_calloc(1, sizeof(t_stack));
if (!start)
ps_stop(NULL, NULL, 2);
start->n = ft_atoi(av[ac]);
start->limit = 0;
start->next = tmp;
tmp = start;
split = ft_split(av[1], ' ');
i = 0;
while (split[i] != NULL)
i++;
while (--i >= 0)
list = fill_stack(list, split[i]);
}
return (start);
return (list);
}
/*