tout casse en prevision de faire des fonctions compatibles avec celles de luke

This commit is contained in:
hugogogo
2021-06-13 11:01:17 +02:00
parent d7a129f3f9
commit 7acfa0491e
7 changed files with 18 additions and 41 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+14 -37
View File
@@ -6,61 +6,38 @@
** then it launch the action (swap, push, rotate)
*/
void action(t_list *pack, void (*sp)(t_list *pack))
void action(t_stack *stack_a, t_stack *stack_b, t_list *solution, int flag,
void (*sp)(t_list *pack))
{
t_stack *stack_a;
t_stack *stack_b;
t_list **solution;
int flag;
stack_a = pack->content;
stack_b = pack->next->content;
solution = pack->next->next->content;
flag = *(int *)(pack->next->next->next->content); // this is a really ugly line :p it's because lst->content is a void*, but we need an int
if (!flag) // if flag == 0, don't print anything
return ;
if (!*solution) // to print only at first call
if (!(*solution)) // to print only at first call
{
print_stack(stack_a, 'a');
print_stack(stack_b, 'b');
}
sp(pack); // the action to execute
ft_putchar('t');
ft_printf("%s\n", (*solution)->content);
ft_putchar('u');
print_stack(stack_a, 'a');
print_stack(stack_b, 'b');
}
t_list *do_pack(t_stack *stack_a, int flag)
{
t_stack *stack_b;
t_list *pack;
if(!(stack_b = ft_calloc(1, sizeof(t_stack))))
ps_stop(stack_a, stack_b, NULL, 2);
pack = ft_lstnew(stack_a);
ft_lstadd_back(&pack, ft_lstnew(stack_b));
ft_lstadd_back(&pack, ft_lstnew(NULL));
ft_lstadd_back(&pack, ft_lstnew(&flag));
return (pack);
}
/*
** this function create the structures "solution" and "stack_b"
** and put their together with "stack_a" in "pack" to facilitate
** the calls of functions. so pack contains :
** - stack_a
** - stack_b
** - solution
** then it calls the algorithm
**
*/
t_list *sort_algo(t_stack *stack, int flag)
t_list *sort_algo(t_stack *a, int f)
{
t_list *pack;
t_stack *b;
t_list *solution;
pack = do_pack(stack, flag);
action(pack, sa);
action(pack, sa);
solution = NULL;
if(!(b = ft_calloc(1, sizeof(t_stack))))
ps_stop(a, b, NULL, 2);
action(a, b, solution, f, sa);
action(a, b, solution, f, sa);
// sa(stack_a, stack_b, &solution);
// sb(stack_a, stack_b, &solution);
// ss(stack_a, stack_b, &solution);
+1 -1
View File
@@ -45,7 +45,7 @@ int main(int ac, char **av)
flag = check_flag(&ac, &av); //check for flag, like print
stack = init_stack(ac, av); // create the list from av[]
result = sort_algo(stack, flag);
print_result(result);
// print_result(result);
ps_stop(stack, NULL, result, 0);
return(0);
}
+3 -3
View File
@@ -4,16 +4,16 @@
void sa(t_list *pack)
{
t_stack *stack_a;
// t_list **solution;
t_list **solution;
int tmp;
stack_a = pack->content;
// solution = pack->next->next->content;
solution = pack->next->next->content;
if (!stack_a->next)
return ;
tmp = stack_a->n;
stack_a->n = stack_a->next->n;
stack_a->next->n = tmp;
// ft_lstadd_back(solution, ft_lstnew(ft_strdup("sa")));
ft_lstadd_back(solution, ft_lstnew(ft_strdup("sa")));
}