plus de leaks yeaaah
This commit is contained in:
BIN
builds/algo.o
BIN
builds/algo.o
Binary file not shown.
Binary file not shown.
BIN
builds/print.o
BIN
builds/print.o
Binary file not shown.
BIN
builds/push.o
BIN
builds/push.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
builds/rotate.o
BIN
builds/rotate.o
Binary file not shown.
BIN
builds/stop.o
BIN
builds/stop.o
Binary file not shown.
BIN
builds/swap.o
BIN
builds/swap.o
Binary file not shown.
@@ -23,7 +23,7 @@ int bubble_sort(t_stack **a, t_stack **b, t_list *solution);
|
||||
int check_flag(int *ac, char ***av);
|
||||
void is_valid(int ac, char **av);
|
||||
t_stack *init_stack(int ac, char **av);
|
||||
t_list *launch_algo(t_stack *stack, int i);
|
||||
t_list *launch_algo(t_stack **a, t_stack **b, int i);
|
||||
|
||||
/*
|
||||
** stop.c
|
||||
@@ -47,8 +47,8 @@ void print_result(t_list *lst, int i);
|
||||
/*
|
||||
** swap
|
||||
*/
|
||||
t_list *sa(t_stack **stack, t_list **lst);
|
||||
t_list *sb(t_stack **stack, t_list **lst);
|
||||
t_list *sa(t_stack **a, t_list **lst);
|
||||
t_list *sb(t_stack **b, t_list **lst);
|
||||
t_list *ss(t_stack **a, t_stack **b, t_list **lst);
|
||||
|
||||
/*
|
||||
|
||||
@@ -40,11 +40,9 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
sa(a, &solution);
|
||||
rra(a, &solution);
|
||||
rrb(b, &solution);
|
||||
/*
|
||||
rrr(a, b, &solution);
|
||||
ra(a, &solution);
|
||||
rb(b, &solution);
|
||||
rr(a, b, &solution);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
16
srcs/print.c
16
srcs/print.c
@@ -2,18 +2,15 @@
|
||||
#include "push_swap.h"
|
||||
|
||||
/*
|
||||
** this function is called at each action (pushes, swapes, rotates)
|
||||
** pointers to the stacks a and b are stored into two first element of list solution (because both lists a and b are not available from every functions, like sa() doesn't receive b in argument)
|
||||
** the function access the list after the two first elements to fill a new element with three things :
|
||||
** - the name of the action (sa, sp, rra, etc)
|
||||
** - the stack a
|
||||
** - the stack b
|
||||
** like this :
|
||||
** this function fill a new element on the chained list like this :
|
||||
** name!a: nb nb nb nb nb!b: nb nb nb
|
||||
** "!" are used to split, it will be turn into :
|
||||
**
|
||||
** it will later be printed like this ("!" is the char to split) :
|
||||
** name
|
||||
** a: nb nb nb nb nb
|
||||
** b: nb nb nb
|
||||
**
|
||||
** or only "name" if not flag -p
|
||||
*/
|
||||
void fill_solution(t_list *solution, char *sp)
|
||||
{
|
||||
@@ -55,6 +52,9 @@ void print_result(t_list *result, int flag)
|
||||
ft_printf(" %s\n", part[2]);
|
||||
}
|
||||
result = result->next;
|
||||
free(part[0]);
|
||||
free(part[1]);
|
||||
free(part[2]);
|
||||
free(part);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ void push(t_stack **dst, t_stack **src)
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
push(a, b);
|
||||
fill_solution(*solution, ft_strdup("pa"));
|
||||
fill_solution(*solution, "pa");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
||||
{
|
||||
push(b, a);
|
||||
fill_solution(*solution, ft_strdup("pb"));
|
||||
fill_solution(*solution, "pb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ void reverse_rotate(t_stack **stack)
|
||||
t_list *rra(t_stack **a, t_list **lst)
|
||||
{
|
||||
reverse_rotate(a);
|
||||
fill_solution(*lst, ft_strdup("rra"));
|
||||
fill_solution(*lst, "rra");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *rrb(t_stack **b, t_list **lst)
|
||||
{
|
||||
reverse_rotate(b);
|
||||
fill_solution(*lst, ft_strdup("rrb"));
|
||||
fill_solution(*lst, "rrb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ t_list *rrr(t_stack **a, t_stack **b, t_list **lst)
|
||||
{
|
||||
reverse_rotate(a);
|
||||
reverse_rotate(b);
|
||||
fill_solution(*lst, ft_strdup("rrr"));
|
||||
fill_solution(*lst, "rrr");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
42
srcs/stop.c
42
srcs/stop.c
@@ -18,10 +18,8 @@ void ps_error(int err)
|
||||
|
||||
void ps_stop(t_stack *stack, t_list *lst, int err)
|
||||
{
|
||||
/*
|
||||
t_stack **a;
|
||||
t_stack **b;
|
||||
t_list *solution;
|
||||
|
||||
if (stack)
|
||||
ft_lstclear((t_list **)&stack, NULL);
|
||||
@@ -31,48 +29,12 @@ void ps_stop(t_stack *stack, t_list *lst, int err)
|
||||
b = lst->next->content;
|
||||
ft_lstclear((t_list **)a, NULL);
|
||||
ft_lstclear((t_list **)b, NULL);
|
||||
lst->content = NULL;
|
||||
lst->next->content = NULL;
|
||||
ft_lstclear(&lst, free);
|
||||
}
|
||||
(void)solution;
|
||||
*/
|
||||
|
||||
/*
|
||||
t_list *tmp;
|
||||
t_stack **aa;
|
||||
t_stack **bb;
|
||||
t_stack *a;
|
||||
t_stack *b;
|
||||
|
||||
aa = lst->content;
|
||||
a = *aa;
|
||||
bb = lst->next->content;
|
||||
b = *bb;
|
||||
// ft_putnbrendl(a->n);
|
||||
// ft_putnbrendl(b->n);
|
||||
|
||||
tmp = lst;
|
||||
lst = lst->next;
|
||||
free(tmp);
|
||||
|
||||
tmp = lst;
|
||||
lst = lst->next;
|
||||
free(tmp);
|
||||
|
||||
while (lst)
|
||||
{
|
||||
tmp = lst->next;
|
||||
free(lst->content);
|
||||
free(lst);
|
||||
lst = tmp;
|
||||
}
|
||||
(void)a;
|
||||
(void)b;
|
||||
*/
|
||||
|
||||
if (err < 0)
|
||||
return ;
|
||||
else if (err > 0)
|
||||
ps_error(err);
|
||||
(void)stack;
|
||||
(void)lst;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user