segfault bizare dans la fonctions qui verifie que la liste est ordonnee

This commit is contained in:
hugogogo
2021-09-27 12:45:07 +02:00
parent db60d412e8
commit 60752e2faf
6 changed files with 25 additions and 12 deletions

Binary file not shown.

Binary file not shown.

BIN
push_swap

Binary file not shown.

View File

@@ -86,7 +86,6 @@ void print_flags(char **part, int flag)
void print_result(t_list *result, int flag)
{
int i;
int j;
char **part;
i = -1;
@@ -99,13 +98,7 @@ void print_result(t_list *result, int flag)
print_flags(part, flag);
ft_putchar('\n');
result = result->next;
j = 0;
while (part[j] != NULL)
{
free(part[j]);
j++;
}
free(part);
ft_free_tab(part);
}
if (flag)
ft_putnbrendl(i);

View File

@@ -1,5 +1,21 @@
#include "push_swap.h"
int is_ordered(t_stack *list)
{
int cmp;
cmp = list->n;
while (list->next != NULL)
{
list = list->next;
ft_printf("n:%i cmp:%i\n", cmp, list->n);
if (list->n < cmp)
return (0);
cmp = list->n;
}
return (1);
}
int check_flag(int *ac, char ***av)
{
if (ft_strcmp((*av)[1], "-p") == 0)
@@ -55,6 +71,7 @@ t_stack *init_stack(int ac, char **av)
i++;
while (--i >= 0)
list = fill_stack(list, split[i]);
ft_free_tab(split);
}
return (list);
}
@@ -96,8 +113,11 @@ int main(int ac, char **av)
flag = check_flag(&ac, &av);
a = init_stack(ac, av);
b = NULL;
solution = launch_algo(&a, &b, flag);
print_result(solution, flag);
if (is_ordered(a) == 1)
{
solution = launch_algo(&a, &b, flag);
print_result(solution, flag);
}
ps_stop(solution, 0);
return (0);
}

View File

@@ -24,7 +24,7 @@ else
exit 0
fi
PRGM=push_swap # path to program
PRGM="push_swap" # path to program
# range of random numbers
RANGE=$(($SIZE * 2))
@@ -33,7 +33,7 @@ LIST=($(shuf -i 0-$RANGE -n $SIZE))
echo -e "${WHITE}test lancé avec la liste de nombres suivantes :${NC}"
echo -e "${LIST[@]}"
OUTPUT=`./$PRGM ${LIST[@]}`
OUTPUT=$(./$PRGM ${LIST[@]})
COUNT=$(echo "$OUTPUT" | wc -l)
RESULT=$(echo "$OUTPUT" | ./checker ${LIST[@]})