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);
|
int check_flag(int *ac, char ***av);
|
||||||
void is_valid(int ac, char **av);
|
void is_valid(int ac, char **av);
|
||||||
t_stack *init_stack(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
|
** stop.c
|
||||||
@@ -47,8 +47,8 @@ void print_result(t_list *lst, int i);
|
|||||||
/*
|
/*
|
||||||
** swap
|
** swap
|
||||||
*/
|
*/
|
||||||
t_list *sa(t_stack **stack, t_list **lst);
|
t_list *sa(t_stack **a, t_list **lst);
|
||||||
t_list *sb(t_stack **stack, t_list **lst);
|
t_list *sb(t_stack **b, t_list **lst);
|
||||||
t_list *ss(t_stack **a, 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);
|
sa(a, &solution);
|
||||||
rra(a, &solution);
|
rra(a, &solution);
|
||||||
rrb(b, &solution);
|
rrb(b, &solution);
|
||||||
/*
|
|
||||||
rrr(a, b, &solution);
|
rrr(a, b, &solution);
|
||||||
ra(a, &solution);
|
ra(a, &solution);
|
||||||
rb(b, &solution);
|
rb(b, &solution);
|
||||||
rr(a, b, &solution);
|
rr(a, b, &solution);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
srcs/print.c
16
srcs/print.c
@@ -2,18 +2,15 @@
|
|||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** this function is called at each action (pushes, swapes, rotates)
|
** this function fill a new element on the chained list like this :
|
||||||
** 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 :
|
|
||||||
** name!a: nb nb nb nb nb!b: nb nb nb
|
** 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
|
** name
|
||||||
** a: nb nb nb nb nb
|
** a: nb nb nb nb nb
|
||||||
** b: nb nb nb
|
** b: nb nb nb
|
||||||
|
**
|
||||||
|
** or only "name" if not flag -p
|
||||||
*/
|
*/
|
||||||
void fill_solution(t_list *solution, char *sp)
|
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]);
|
ft_printf(" %s\n", part[2]);
|
||||||
}
|
}
|
||||||
result = result->next;
|
result = result->next;
|
||||||
|
free(part[0]);
|
||||||
|
free(part[1]);
|
||||||
|
free(part[2]);
|
||||||
free(part);
|
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)
|
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||||
{
|
{
|
||||||
push(a, b);
|
push(a, b);
|
||||||
fill_solution(*solution, ft_strdup("pa"));
|
fill_solution(*solution, "pa");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
||||||
{
|
{
|
||||||
push(b, a);
|
push(b, a);
|
||||||
fill_solution(*solution, ft_strdup("pb"));
|
fill_solution(*solution, "pb");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,48 +36,39 @@ t_stack *init_stack(int ac, char **av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** this function creates the stack b and the list solution
|
** the chained list "solution" is created with specials first two elements :
|
||||||
** then it init the list solution with :
|
** they are pointers to stack a and b, so it can be accessed by fill_solution()
|
||||||
** - first element : pointer to stack a
|
**
|
||||||
** - secnd element : pointer to stack b
|
** because when an action like sa() is called it desn't get stack_b as a parameter
|
||||||
** - third element : initial values of stack a (in case of flag -p)
|
** so when it calls fill_solution(), this function needs an access to stack_b in
|
||||||
** then it calls the sorting algorithm
|
** case of flag -p, to fill the state of the stacks
|
||||||
** then it calls ps_stop() to free everything that needs to be freed
|
|
||||||
*/
|
*/
|
||||||
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;
|
t_list *solution;
|
||||||
|
|
||||||
b = NULL;
|
solution = ft_lstnew(a);
|
||||||
solution = ft_lstnew(&a);
|
ft_lstadd_back(&solution, ft_lstnew(b));
|
||||||
ft_lstadd_back(&solution, ft_lstnew(&b));
|
|
||||||
if (flag)
|
if (flag)
|
||||||
fill_solution(solution, "start");
|
fill_solution(solution, "start");
|
||||||
hugo_sort(&a, &b, solution);
|
hugo_sort(a, b, solution);
|
||||||
//bubble_sort(&a, &b, solution);
|
//bubble_sort(&a, &b, solution);
|
||||||
return (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)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_stack *stack;
|
t_stack *a;
|
||||||
t_list *result;
|
t_stack *b;
|
||||||
|
t_list *solution;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
is_valid(ac, av);
|
is_valid(ac, av);
|
||||||
flag = check_flag(&ac, &av);
|
flag = check_flag(&ac, &av);
|
||||||
stack = init_stack(ac, av);
|
a = init_stack(ac, av);
|
||||||
result = launch_algo(stack, flag);
|
b = NULL;
|
||||||
print_result(result, flag);
|
solution = launch_algo(&a, &b, flag);
|
||||||
ps_stop(NULL, result, 0);
|
print_result(solution, flag);
|
||||||
|
ps_stop(NULL, solution, 0);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ void reverse_rotate(t_stack **stack)
|
|||||||
t_list *rra(t_stack **a, t_list **lst)
|
t_list *rra(t_stack **a, t_list **lst)
|
||||||
{
|
{
|
||||||
reverse_rotate(a);
|
reverse_rotate(a);
|
||||||
fill_solution(*lst, ft_strdup("rra"));
|
fill_solution(*lst, "rra");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_list *rrb(t_stack **b, t_list **lst)
|
t_list *rrb(t_stack **b, t_list **lst)
|
||||||
{
|
{
|
||||||
reverse_rotate(b);
|
reverse_rotate(b);
|
||||||
fill_solution(*lst, ft_strdup("rrb"));
|
fill_solution(*lst, "rrb");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +37,6 @@ t_list *rrr(t_stack **a, t_stack **b, t_list **lst)
|
|||||||
{
|
{
|
||||||
reverse_rotate(a);
|
reverse_rotate(a);
|
||||||
reverse_rotate(b);
|
reverse_rotate(b);
|
||||||
fill_solution(*lst, ft_strdup("rrr"));
|
fill_solution(*lst, "rrr");
|
||||||
return (NULL);
|
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)
|
void ps_stop(t_stack *stack, t_list *lst, int err)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
t_stack **a;
|
t_stack **a;
|
||||||
t_stack **b;
|
t_stack **b;
|
||||||
t_list *solution;
|
|
||||||
|
|
||||||
if (stack)
|
if (stack)
|
||||||
ft_lstclear((t_list **)&stack, NULL);
|
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;
|
b = lst->next->content;
|
||||||
ft_lstclear((t_list **)a, NULL);
|
ft_lstclear((t_list **)a, NULL);
|
||||||
ft_lstclear((t_list **)b, NULL);
|
ft_lstclear((t_list **)b, NULL);
|
||||||
|
lst->content = NULL;
|
||||||
|
lst->next->content = NULL;
|
||||||
ft_lstclear(&lst, free);
|
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)
|
if (err < 0)
|
||||||
return ;
|
return ;
|
||||||
else if (err > 0)
|
else if (err > 0)
|
||||||
ps_error(err);
|
ps_error(err);
|
||||||
(void)stack;
|
|
||||||
(void)lst;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user