ajout flag -P de debug
This commit is contained in:
BIN
builds/algo.o
BIN
builds/algo.o
Binary file not shown.
BIN
builds/print.o
BIN
builds/print.o
Binary file not shown.
Binary file not shown.
@@ -42,7 +42,9 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *lst);
|
||||
/*
|
||||
** print.c
|
||||
*/
|
||||
void mark_step(t_list *solution);
|
||||
void fill_solution(t_list *lst, char *s);
|
||||
char *fill_line(t_stack *list, char *stack);
|
||||
void print_result(t_list *lst, int i);
|
||||
|
||||
/*
|
||||
|
||||
10
srcs/algo.c
10
srcs/algo.c
@@ -63,8 +63,14 @@ int divide_a(t_stack **a, t_stack **b, t_list *solution)
|
||||
(void)solution;
|
||||
list_size = sublist_size(*a);
|
||||
pivot = find_pivot(*a, list_size);
|
||||
ft_putnbrendl(list_size);
|
||||
ft_putnbrendl(pivot);
|
||||
while (list_size-- > 0)
|
||||
{
|
||||
if ((*a)->n >= pivot)
|
||||
ra(a, &solution);
|
||||
else
|
||||
pb(b, a, &solution);
|
||||
}
|
||||
mark_step(solution);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
43
srcs/print.c
43
srcs/print.c
@@ -1,5 +1,31 @@
|
||||
#include "push_swap.h"
|
||||
|
||||
char *fill_line(t_stack *list, char *stack)
|
||||
{
|
||||
while (list != NULL)
|
||||
{
|
||||
if (list->limit == 1)
|
||||
stack = ft_strjoinfree(ft_strdup("]"), stack);
|
||||
stack = ft_strjoinfree(ft_itoa(list->n), stack);
|
||||
if (list->limit == 1)
|
||||
stack = ft_strjoinfree(ft_strdup("["), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
list = list->next;
|
||||
}
|
||||
return (stack);
|
||||
}
|
||||
|
||||
void mark_step(t_list *solution)
|
||||
{
|
||||
char *line;
|
||||
|
||||
while (solution->next != NULL)
|
||||
solution = solution->next;
|
||||
line = solution->content;
|
||||
line = ft_strjoinfree(line, ft_strdup("!1"));
|
||||
solution->content = line;
|
||||
}
|
||||
|
||||
/*
|
||||
** this function is called by actions like sa()
|
||||
** it fills a new str element on the chained list like this :
|
||||
@@ -29,19 +55,9 @@ void fill_solution(t_list *solution, char *sp)
|
||||
a = *(t_stack **)(solution->content);
|
||||
b = *(t_stack **)(solution->next->content);
|
||||
stack = ft_strjoinfree(ft_strdup("!"), ft_strdup(sp));
|
||||
while (a != NULL)
|
||||
{
|
||||
stack = ft_strjoinfree(ft_itoa(a->n), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
a = a->next;
|
||||
}
|
||||
stack = fill_line(a, stack);
|
||||
stack = ft_strjoinfree(ft_strdup("!a:"), stack);
|
||||
while (b != NULL)
|
||||
{
|
||||
stack = ft_strjoinfree(ft_itoa(b->n), stack);
|
||||
stack = ft_strjoinfree(ft_strdup(" "), stack);
|
||||
b = b->next;
|
||||
}
|
||||
stack = fill_line(b, stack);
|
||||
stack = ft_strjoinfree(ft_strdup("b:"), stack);
|
||||
ft_lstadd_back(&solution, ft_lstnew(stack));
|
||||
}
|
||||
@@ -58,7 +74,7 @@ void print_result(t_list *result, int flag)
|
||||
i++;
|
||||
part = ft_split(result->content, '!');
|
||||
ft_printf("%s\n", part[2]);
|
||||
if (flag)
|
||||
if (flag == 1 || (flag == 2 && part[3] != NULL))
|
||||
{
|
||||
ft_printf(" %s\n", part[1]);
|
||||
ft_printf(" %s\n", part[0]);
|
||||
@@ -67,6 +83,7 @@ void print_result(t_list *result, int flag)
|
||||
free(part[0]);
|
||||
free(part[1]);
|
||||
free(part[2]);
|
||||
free(part[3]);
|
||||
free(part);
|
||||
}
|
||||
if (flag)
|
||||
|
||||
@@ -10,11 +10,19 @@ void is_valid(int ac, char **av)
|
||||
|
||||
int check_flag(int *ac, char ***av)
|
||||
{
|
||||
if (ft_strcmp((*av)[1], "-p") != 0)
|
||||
return (0);
|
||||
(*av)++;
|
||||
(*ac)--;
|
||||
return (1);
|
||||
if (ft_strcmp((*av)[1], "-p") == 0)
|
||||
{
|
||||
(*av)++;
|
||||
(*ac)--;
|
||||
return (1);
|
||||
}
|
||||
if (ft_strcmp((*av)[1], "-P") == 0)
|
||||
{
|
||||
(*av)++;
|
||||
(*ac)--;
|
||||
return (2);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
t_stack *init_stack(int ac, char **av)
|
||||
@@ -48,7 +56,10 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag)
|
||||
solution = ft_lstnew(a);
|
||||
ft_lstadd_back(&solution, ft_lstnew(b));
|
||||
if (flag)
|
||||
{
|
||||
fill_solution(solution, "start");
|
||||
mark_step(solution);
|
||||
}
|
||||
hugo_sort(a, b, solution);
|
||||
// bubble_sort(a, b, solution);
|
||||
return (solution);
|
||||
|
||||
Reference in New Issue
Block a user