diff --git a/Makefile b/Makefile index 7399e93..55cff5f 100644 --- a/Makefile +++ b/Makefile @@ -75,5 +75,13 @@ leaks: clean $(NAME) valgrind: clean $(NAME) valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) -p 4 67 9 76 98 7 1 +testp : clean $(NAME) + ./$(NAME) -p 76 81 10 11 12 15 14 27 34 28 17 18 19 20 36 21 23 37 22 24 25 26 29 30 31 72 33 53 46 32 35 91 38 39 40 45 78 41 57 71 54 43 42 44 66 50 47 48 49 79 51 56 93 65 64 63 67 90 58 59 60 62 61 87 68 74 82 85 86 77 75 70 73 89 69 83 84 92 88 95 94 96 99 97 98 100 1 2 3 4 5 6 7 8 9 52 16 55 80 13 + +test : clean $(NAME) + ./$(NAME) 76 81 10 11 12 15 14 27 34 28 17 18 19 20 36 21 23 37 22 24 25 26 29 30 31 72 33 53 46 32 35 91 38 39 40 45 78 41 57 71 54 43 42 44 66 50 47 48 49 79 51 56 93 65 64 63 67 90 58 59 60 62 61 87 68 74 82 85 86 77 75 70 73 89 69 83 84 92 88 95 94 96 99 97 98 100 1 2 3 4 5 6 7 8 9 52 16 55 80 13 + +# 83 94 28 17 18 36 20 33 39 53 23 37 22 24 45 25 29 78 26 30 31 72 46 32 35 70 38 93 50 91 40 5 41 57 71 66 92 54 67 75 65 42 43 44 74 79 47 48 49 88 51 63 7 68 87 61 82 4 90 58 59 62 60 1 85 89 96 98 100 84 69 77 73 3 86 99 97 6 2 9 8 52 80 16 55 13 76 81 10 11 12 15 14 27 34 56 21 64 95 19 + .PHONY: all clean fclean re gcc diff --git a/builds/print.o b/builds/print.o index 2536b4e..a3dd5d7 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o index 82d7e64..2105527 100644 Binary files a/builds/push.o and b/builds/push.o differ diff --git a/builds/push_swap.o b/builds/push_swap.o index b1eccf6..aeea254 100644 Binary files a/builds/push_swap.o and b/builds/push_swap.o differ diff --git a/builds/reverse_rotate.o b/builds/reverse_rotate.o index 4d163fa..f59aef6 100644 Binary files a/builds/reverse_rotate.o and b/builds/reverse_rotate.o differ diff --git a/builds/rotate.o b/builds/rotate.o index 3fac3c2..474239d 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/swap.o b/builds/swap.o index 6b4afbb..a468b0f 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/compare_pushswap.sh b/compare_pushswap.sh new file mode 100755 index 0000000..ca8f39d --- /dev/null +++ b/compare_pushswap.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# usage of arguments +if [ $# -eq 3 ] +then # names = path to programs + NAME1=$1 + NAME2=$2 + PRGRM1=$1 # path to programs + PRGRM2=$2 + SIZE=$3 # size of the list +elif [ $# -eq 5 ] +then # names given in arguments + NAME1=$1 + NAME2=$3 + PRGRM1=$2 # path to programs + PRGRM2=$4 + SIZE=$5 # size of the list +else + echo "usage : ./compare_pushswap file1 file2 nb" + echo "or : ./compare_pushswap name1 file1 name2 file2 nb" + exit 0 +fi + +# range of random numbers +RANGE=100 +if [ $SIZE -gt 99 ]; then RANGE=1000; fi +if [ $SIZE -gt 999 ]; then echo "size too big"; exit 0; fi + +# generate the list of randoms differents numbers +LIST=($(shuf -i 0-$RANGE -n $SIZE)) +echo -e "${LIST[@]}" + +# player equal number of line of programm output +PLAYER1=$(./$PRGRM1 ${LIST[@]} | wc -l) +PLAYER2=$(./$PRGRM2 ${LIST[@]} | wc -l) + +# colors variables +RED='\033[1;31m' +GREEN='\033[1;32m' +NC='\033[0m' + +if [ $PLAYER1 -lt $PLAYER2 ] +then + COLOR1=$GREEN + COLOR2=$RED +else + COLOR1=$RED + COLOR2=$GREEN +fi + +echo -e "${COLOR1}$NAME1 : $PLAYER1${NC}" +echo -e "${COLOR2}$NAME2 : $PLAYER2${NC}" diff --git a/push_swap b/push_swap index 9986793..3bc14bd 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/print.c b/srcs/print.c index 1144421..36da8de 100644 --- a/srcs/print.c +++ b/srcs/print.c @@ -39,11 +39,14 @@ void fill_solution(t_list *solution, char *sp) void print_result(t_list *result, int flag) { + int i; char **part; + i = -1; result = result->next->next; while (result) { + i++; part = ft_split(result->content, '!'); ft_printf("%s\n", part[0]); if (flag) @@ -57,4 +60,6 @@ void print_result(t_list *result, int flag) free(part[2]); free(part); } + if (flag) + ft_putnbrendl(i); } diff --git a/srcs/push.c b/srcs/push.c index c6a2a1b..561cc7d 100644 --- a/srcs/push.c +++ b/srcs/push.c @@ -5,13 +5,14 @@ void push(t_stack **dst, t_stack **src) t_stack *tmp1; t_stack *tmp2; - if (!((*src)->next)) - return ; - tmp1 = *src; - tmp2 = *dst; - *src = (*src)->next; - tmp1->next = tmp2; - *dst = tmp1; + if (*src) + { + tmp1 = *src; + tmp2 = *dst; + *src = (*src)->next; + tmp1->next = tmp2; + *dst = tmp1; + } } t_list *pa(t_stack **a, t_stack **b, t_list **solution) diff --git a/srcs/push_swap.c b/srcs/push_swap.c index c025223..7203919 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -47,10 +47,10 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag) ft_lstadd_back(&solution, ft_lstnew(b)); if (flag) fill_solution(solution, "start"); - hugo_sort(a, b, solution); + // hugo_sort(a, b, solution); + bubble_sort(a, b, solution); return (solution); } -// bubble_sort(&a, &b, solution); int main(int ac, char **av) { diff --git a/srcs/reverse_rotate.c b/srcs/reverse_rotate.c index 57a61bb..38567ba 100644 --- a/srcs/reverse_rotate.c +++ b/srcs/reverse_rotate.c @@ -5,17 +5,18 @@ void reverse_rotate(t_stack **stack) t_stack *tmp; t_stack *before; - tmp = *stack; - if (!tmp || !(tmp->next)) - return ; - while (tmp->next) + if (*stack && (*stack)->next) { - before = tmp; - tmp = tmp->next; + tmp = *stack; + while (tmp->next) + { + before = tmp; + tmp = tmp->next; + } + tmp->next = *stack; + *stack = tmp; + before->next = NULL; } - tmp->next = *stack; - *stack = tmp; - before->next = NULL; } t_list *rra(t_stack **a, t_list **lst) diff --git a/srcs/rotate.c b/srcs/rotate.c index 9988136..3b9f861 100644 --- a/srcs/rotate.c +++ b/srcs/rotate.c @@ -5,15 +5,16 @@ void rotate(t_stack **stack) t_stack *tmp; t_stack *first; - first = *stack; - tmp = *stack; - if (!tmp || !(tmp->next)) - return ; - *stack = (*stack)->next; - while (tmp->next) - tmp = tmp->next; - tmp->next = first; - first->next = NULL; + if (*stack && (*stack)->next) + { + first = *stack; + tmp = *stack; + *stack = (*stack)->next; + while (tmp->next) + tmp = tmp->next; + tmp->next = first; + first->next = NULL; + } } t_list *ra(t_stack **a, t_list **lst) diff --git a/srcs/swap.c b/srcs/swap.c index 9fd4048..edc55cb 100644 --- a/srcs/swap.c +++ b/srcs/swap.c @@ -4,12 +4,13 @@ void swap(t_stack **stack) { t_stack *tmp; - tmp = *stack; - if (!(tmp->next)) - return ; - *stack = (*stack)->next; - tmp->next = (*stack)->next; - (*stack)->next = tmp; + if (*stack && (*stack)->next) + { + tmp = *stack; + *stack = (*stack)->next; + tmp->next = (*stack)->next; + (*stack)->next = tmp; + } } t_list *sa(t_stack **a, t_list **solution)