pile b ne fonctionne pas
This commit is contained in:
@@ -5,7 +5,7 @@ void hugo_sort(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
(void)b;
|
||||
sa(a, solution);
|
||||
sa(a, solution);
|
||||
sa(a, solution);
|
||||
pb(b, a, solution);
|
||||
sb(a, solution);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
/*
|
||||
static int search_smaller(t_stack *stack, int *smaller)
|
||||
{
|
||||
int i;
|
||||
@@ -56,3 +57,4 @@ int bubble_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
pa(a, b, &solution);
|
||||
return (1);
|
||||
}
|
||||
*/
|
||||
|
||||
25
srcs/print.c
25
srcs/print.c
@@ -1,10 +1,28 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void fill_solution(t_stack *a, t_stack *b, t_list **solution, char *sp)
|
||||
/*
|
||||
** 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 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
|
||||
** "!" are used to split, it will be turn into :
|
||||
** name
|
||||
** a: nb nb nb nb nb
|
||||
** b: nb nb nb
|
||||
*/
|
||||
void fill_solution(t_list **solution, char *sp)
|
||||
{
|
||||
t_stack *a;
|
||||
t_stack *b;
|
||||
char *stack;
|
||||
|
||||
a = (*solution)->content;
|
||||
b = (*solution)->next->content;
|
||||
stack = ft_strdup(sp);
|
||||
stack = ft_strjoinfree(stack, ft_strdup("!a:"));
|
||||
while(a)
|
||||
@@ -17,7 +35,7 @@ void fill_solution(t_stack *a, t_stack *b, t_list **solution, char *sp)
|
||||
while(b)
|
||||
{
|
||||
stack = ft_strjoinfree(stack, ft_strdup(" "));
|
||||
stack = ft_strjoinfree(stack, ft_itoa(a->n));
|
||||
stack = ft_strjoinfree(stack, ft_itoa(b->n));
|
||||
b = b->next;
|
||||
}
|
||||
ft_lstadd_back(solution, ft_lstnew(stack));
|
||||
@@ -26,7 +44,8 @@ void fill_solution(t_stack *a, t_stack *b, t_list **solution, char *sp)
|
||||
void print_result(t_list *result, int flag)
|
||||
{
|
||||
char **part;
|
||||
|
||||
|
||||
result = result->next->next;
|
||||
if (!flag)
|
||||
result = result->next;
|
||||
while (result)
|
||||
|
||||
37
srcs/push.c
Normal file
37
srcs/push.c
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
t_stack *tmp;
|
||||
|
||||
if (!(tmp = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(*a, *b, *solution, 2);
|
||||
tmp->n = (*b)->n;
|
||||
tmp->next = NULL;
|
||||
(*a)->next = tmp;
|
||||
fill_solution(solution, ft_strdup("pa"));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *pb(t_stack **dst, t_stack **src, t_list **solution)
|
||||
{
|
||||
t_stack *a;
|
||||
t_stack *b;
|
||||
t_stack *tmp;
|
||||
|
||||
a = *src;
|
||||
b = *dst;
|
||||
|
||||
if (!(b = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(a, b, *solution, 2);
|
||||
b->n = a->n;
|
||||
b->next = NULL;
|
||||
|
||||
tmp = a->next;
|
||||
a->n = a->next->n;
|
||||
a->next = a->next->next;
|
||||
free(tmp);
|
||||
fill_solution(solution, ft_strdup("pa"));
|
||||
return (NULL);
|
||||
}
|
||||
@@ -49,7 +49,10 @@ 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 initial values of stack a (in case of flag -p)
|
||||
** 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
|
||||
*/
|
||||
@@ -58,11 +61,13 @@ t_list *launch_algo(t_stack *a)
|
||||
t_stack *b;
|
||||
t_list *solution;
|
||||
|
||||
if(!(b = ft_calloc(1, sizeof(t_stack))))
|
||||
ps_stop(a, b, NULL, 2);
|
||||
b = NULL;
|
||||
solution = NULL;
|
||||
fill_solution(a, NULL, &solution, ft_strdup("start"));
|
||||
ft_lstadd_back(&solution, ft_lstnew(a));
|
||||
ft_lstadd_back(&solution, ft_lstnew(b));
|
||||
fill_solution(&solution, ft_strdup("start"));
|
||||
hugo_sort(&a, &b, &solution);
|
||||
//bubble_sort(&a, &b, solution);
|
||||
ps_stop(NULL, b, NULL, -1);
|
||||
return (solution);
|
||||
}
|
||||
|
||||
6
srcs/reverse_rotate.c
Normal file
6
srcs/reverse_rotate.c
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *rra(t_stack **stack, t_list **lst);
|
||||
t_list *rrb(t_stack **stack, t_list **lst);
|
||||
t_list *rrr(t_stack **a, t_stack **b, t_list **lst);
|
||||
7
srcs/rotate.c
Normal file
7
srcs/rotate.c
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *ra(t_stack **stack, t_list **lst);
|
||||
t_list *rb(t_stack **stack, t_list **lst);
|
||||
t_list *rr(t_stack **a, t_stack **b, t_list **lst);
|
||||
|
||||
13
srcs/swap.c
13
srcs/swap.c
@@ -12,7 +12,18 @@ t_list *sa(t_stack **stack, t_list **solution)
|
||||
tmp = a->n;
|
||||
a->n = a->next->n;
|
||||
a->next->n = tmp;
|
||||
fill_solution(*stack, NULL, solution, ft_strdup("sa"));
|
||||
fill_solution(solution, ft_strdup("sa"));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *sb(t_stack **b, t_list **solution)
|
||||
{
|
||||
return (sa(b, solution));
|
||||
}
|
||||
|
||||
t_list *ss(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
sa(a, solution);
|
||||
sa(b, solution);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user