plus de leaks yeaaah

This commit is contained in:
hugogogo
2021-06-27 13:30:04 +02:00
parent c38f2383f7
commit aa65191b11
17 changed files with 36 additions and 85 deletions

View File

@@ -36,48 +36,39 @@ t_stack *init_stack(int ac, char **av)
}
/*
** this function creates the stack b and the list solution
** then it init the list solution with :
** - first element : pointer to stack a
** - secnd element : pointer to stack b
** - third element : initial values of stack a (in case of flag -p)
** then it calls the sorting algorithm
** then it calls ps_stop() to free everything that needs to be freed
** the chained list "solution" is created with specials first two elements :
** they are pointers to stack a and b, so it can be accessed by fill_solution()
**
** because when an action like sa() is called it desn't get stack_b as a parameter
** so when it calls fill_solution(), this function needs an access to stack_b in
** case of flag -p, to fill the state of the stacks
*/
t_list *launch_algo(t_stack *a, int flag)
t_list *launch_algo(t_stack **a, t_stack **b, int flag)
{
t_stack *b;
t_list *solution;
b = NULL;
solution = ft_lstnew(&a);
ft_lstadd_back(&solution, ft_lstnew(&b));
solution = ft_lstnew(a);
ft_lstadd_back(&solution, ft_lstnew(b));
if (flag)
fill_solution(solution, "start");
hugo_sort(&a, &b, solution);
hugo_sort(a, b, solution);
//bubble_sort(&a, &b, solution);
return (solution);
}
/*
** this programme will sort a list
** this function first check the validity of the arguments
** then it checks for flags (currently only -p)
** then it parse the list into a linked list
** then it calls the sorting algorithm (it actually calls a launch function that will execute some actions and calls the sorting algorithm)
** and finally it frees everything and leaves
*/
int main(int ac, char **av)
{
t_stack *stack;
t_list *result;
t_stack *a;
t_stack *b;
t_list *solution;
int flag;
is_valid(ac, av);
flag = check_flag(&ac, &av);
stack = init_stack(ac, av);
result = launch_algo(stack, flag);
print_result(result, flag);
ps_stop(NULL, result, 0);
a = init_stack(ac, av);
b = NULL;
solution = launch_algo(&a, &b, flag);
print_result(solution, flag);
ps_stop(NULL, solution, 0);
return(0);
}