diff --git a/builds/print.o b/builds/print.o index fa902f2..67e90cc 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index 7118121..145675d 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/push_swap b/push_swap index 3fbf108..9a1a1fd 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/print.c b/srcs/print.c index eebd0f8..8eb2226 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -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); diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 269e58a..e792059 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -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); } diff --git a/tester.sh b/tester.sh index 0e675b9..6411cfe 100644 --- a/tester.sh +++ b/tester.sh @@ -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[@]})