debugage de dup stack a
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.
42
srcs/algo.c
42
srcs/algo.c
@@ -1,11 +1,51 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *dup_n_fill(t_stack *a)
|
||||
{
|
||||
t_list *sort;
|
||||
int *i;
|
||||
int j;
|
||||
int *x;
|
||||
|
||||
j = 0;
|
||||
i = (int *)ft_calloc(3, sizeof(int));
|
||||
sort = NULL;
|
||||
while(a)
|
||||
{
|
||||
if(sort){x = sort->content; ft_printf("[%i / ", x[0]);}
|
||||
|
||||
i[0] = a->n;
|
||||
i[1] = j;
|
||||
i[2] = 0;
|
||||
|
||||
if(sort){x = sort->content; ft_printf("%i] ", x[0]);}
|
||||
|
||||
ft_lstadd_back(&sort, ft_lstnew(i));
|
||||
|
||||
x = sort->content; ft_printf("[%i]\n", x[0]);
|
||||
|
||||
a = a->next;
|
||||
j++;
|
||||
}
|
||||
return (sort);
|
||||
}
|
||||
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
(void)b;
|
||||
(void)a;
|
||||
(void)solution;
|
||||
t_list *sort;
|
||||
|
||||
pb(b, a, &solution);
|
||||
sort = dup_n_fill(*a);
|
||||
int *i;
|
||||
while(sort)
|
||||
{
|
||||
i = sort->content;
|
||||
ft_printf("%i - %i - %i\n", i[0], i[1], i[2]);
|
||||
sort = sort->next;
|
||||
}
|
||||
/*
|
||||
sa(a, &solution);
|
||||
pb(b, a, &solution);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
/*
|
||||
static int search_smaller(t_stack *stack, int *smaller)
|
||||
{
|
||||
int i;
|
||||
@@ -57,4 +56,3 @@ int bubble_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
pa(a, b, &solution);
|
||||
return (1);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@ void fill_solution(t_list *solution, char *sp)
|
||||
t_stack *b;
|
||||
char *stack;
|
||||
|
||||
print_test(solution, "fill_solution (beginning)");
|
||||
tmp1 = solution->content;
|
||||
tmp2 = solution->next->content;
|
||||
a = *tmp1;
|
||||
@@ -43,16 +42,13 @@ print_test(solution, "fill_solution (beginning)");
|
||||
stack = ft_strjoinfree(stack, ft_itoa(b->n));
|
||||
b = b->next;
|
||||
}
|
||||
print_test(solution, "fill_solu. (bfr add_back)");
|
||||
ft_lstadd_back(&solution, ft_lstnew(stack));
|
||||
print_test(solution, "fill_solu. (aft add_back)");
|
||||
}
|
||||
|
||||
void print_result(t_list *result, int flag)
|
||||
{
|
||||
char **part;
|
||||
|
||||
print_test(result, "print result ");
|
||||
result = result->next->next;
|
||||
while (result)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
/*
|
||||
** this function check errors in the arguments
|
||||
** like, is there arguments, and are they a valid list without equals values
|
||||
** if there are no arguments it calls the stop function with value 1 to print usage
|
||||
*/
|
||||
void is_valid(int ac, char **av)
|
||||
{
|
||||
if (ac < 2)
|
||||
@@ -14,10 +9,6 @@ void is_valid(int ac, char **av)
|
||||
// check more error
|
||||
}
|
||||
|
||||
/*
|
||||
** this function check if there are flags (currently only one flag) :
|
||||
** -p to print the evolution of the list while the sorting is done
|
||||
*/
|
||||
int check_flag(int *ac, char ***av)
|
||||
{
|
||||
if (ft_strcmp((*av)[1], "-p") != 0)
|
||||
@@ -27,9 +18,6 @@ int check_flag(int *ac, char ***av)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
** create the stack for list a, as a linked list, and fill it with the values given in arguments argv
|
||||
*/
|
||||
t_stack *init_stack(int ac, char **av)
|
||||
{
|
||||
t_stack *start;
|
||||
@@ -64,13 +52,10 @@ t_list *launch_algo(t_stack *a, int flag)
|
||||
b = NULL;
|
||||
solution = ft_lstnew(&a);
|
||||
ft_lstadd_back(&solution, ft_lstnew(&b));
|
||||
print_test(solution, "launch_algo ");
|
||||
if (flag)
|
||||
fill_solution(solution, ft_strdup("start"));
|
||||
print_test(solution, "launch_algo (after fill) ");
|
||||
hugo_sort(&a, &b, solution);
|
||||
//bubble_sort(&a, &b, solution);
|
||||
print_test(solution, "launch_algo (bfr return) ");
|
||||
return (solution);
|
||||
}
|
||||
|
||||
@@ -92,8 +77,6 @@ int main(int ac, char **av)
|
||||
flag = check_flag(&ac, &av);
|
||||
stack = init_stack(ac, av);
|
||||
result = launch_algo(stack, flag);
|
||||
print_test(result, "main ");
|
||||
//sa(&stack, &result);
|
||||
print_result(result, flag);
|
||||
ps_stop(NULL, result, 0);
|
||||
return(0);
|
||||
|
||||
@@ -20,14 +20,14 @@ void rotate(t_stack **stack)
|
||||
t_list *ra(t_stack **a, t_list **lst)
|
||||
{
|
||||
rotate(a);
|
||||
fill_solution(*lst, ft_strdup("ra"));
|
||||
fill_solution(*lst, "ra");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *rb(t_stack **b, t_list **lst)
|
||||
{
|
||||
rotate(b);
|
||||
fill_solution(*lst, ft_strdup("rb"));
|
||||
fill_solution(*lst, "rb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ t_list *rr(t_stack **a, t_stack **b, t_list **lst)
|
||||
{
|
||||
rotate(a);
|
||||
rotate(b);
|
||||
fill_solution(*lst, ft_strdup("rr"));
|
||||
fill_solution(*lst, "rr");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
27
srcs/stop.c
27
srcs/stop.c
@@ -1,31 +1,6 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void print_test(t_list *lst, char *s)
|
||||
{
|
||||
t_stack **tmpa;
|
||||
t_stack **tmpb;
|
||||
t_stack *a;
|
||||
t_stack *b;
|
||||
|
||||
tmpa = lst->content;
|
||||
tmpb = lst->next->content;
|
||||
a = *tmpa;
|
||||
b = *tmpb;
|
||||
ft_printf("%s -> a: %12i . %12i . ", s, tmpa, a);
|
||||
if (a)
|
||||
ft_printf("%12i", a->n);
|
||||
else
|
||||
ft_printf(" NULL");
|
||||
ft_printf(" | b: %12i . %12i . ", tmpb, b);
|
||||
if (b)
|
||||
ft_printf("%12i \n", b->n);
|
||||
else
|
||||
ft_printf(" NULL\n");
|
||||
|
||||
//ft_printf("%s -> a: %i , %i , %i / b: %i , %i, %i \n", s, tmpa, a, a->n, tmpb, b, b->n);
|
||||
}
|
||||
|
||||
void ps_usage(void)
|
||||
{
|
||||
ft_printf("usage :\n");
|
||||
@@ -94,8 +69,6 @@ void ps_stop(t_stack *stack, t_list *lst, int err)
|
||||
(void)b;
|
||||
*/
|
||||
|
||||
print_test(lst, "ps_stop ");
|
||||
|
||||
if (err < 0)
|
||||
return ;
|
||||
else if (err > 0)
|
||||
|
||||
@@ -16,14 +16,14 @@ void swap(t_stack **stack)
|
||||
t_list *sa(t_stack **a, t_list **solution)
|
||||
{
|
||||
swap(a);
|
||||
fill_solution(*solution, ft_strdup("sa"));
|
||||
fill_solution(*solution, "sa");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *sb(t_stack **b, t_list **solution)
|
||||
{
|
||||
swap(b);
|
||||
fill_solution(*solution, ft_strdup("sb"));
|
||||
fill_solution(*solution, "sb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ t_list *ss(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
swap(a);
|
||||
swap(b);
|
||||
fill_solution(*solution, ft_strdup("sb"));
|
||||
fill_solution(*solution, "sb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user