diff --git a/builds/algo.o b/builds/algo.o index b06c8b1..8011c09 100644 Binary files a/builds/algo.o and b/builds/algo.o differ diff --git a/builds/algo_bubble_sort.o b/builds/algo_bubble_sort.o index d22287c..0118619 100644 Binary files a/builds/algo_bubble_sort.o and b/builds/algo_bubble_sort.o differ diff --git a/builds/minisort.o b/builds/minisort.o index 4febd29..77a35e4 100644 Binary files a/builds/minisort.o and b/builds/minisort.o differ diff --git a/builds/minisort_2ways_bubble_sort.o b/builds/minisort_2ways_bubble_sort.o index 6e11305..c0f9154 100644 Binary files a/builds/minisort_2ways_bubble_sort.o and b/builds/minisort_2ways_bubble_sort.o differ diff --git a/builds/minisort_by_rank.o b/builds/minisort_by_rank.o index cbe2305..73164d2 100644 Binary files a/builds/minisort_by_rank.o and b/builds/minisort_by_rank.o differ diff --git a/builds/print.o b/builds/print.o index e9e2f52..fa902f2 100644 Binary files a/builds/print.o and b/builds/print.o differ diff --git a/builds/push.o b/builds/push.o index 4681227..42eb862 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 30d043e..16c3d97 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 2184f54..74d99f8 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 805b948..a636273 100644 Binary files a/builds/rotate.o and b/builds/rotate.o differ diff --git a/builds/sort_utils.o b/builds/sort_utils.o index b072987..6a57dae 100644 Binary files a/builds/sort_utils.o and b/builds/sort_utils.o differ diff --git a/builds/special_sorts_3_5.o b/builds/special_sorts_3_5.o index 9aa3774..b9422cb 100644 Binary files a/builds/special_sorts_3_5.o and b/builds/special_sorts_3_5.o differ diff --git a/builds/stop.o b/builds/stop.o index 908a2e5..8f27a04 100644 Binary files a/builds/stop.o and b/builds/stop.o differ diff --git a/builds/swap.o b/builds/swap.o index 6b6af83..8894691 100644 Binary files a/builds/swap.o and b/builds/swap.o differ diff --git a/includes/push_swap.h b/includes/push_swap.h index 1dd5765..d2b993b 100644 --- a/includes/push_swap.h +++ b/includes/push_swap.h @@ -5,6 +5,8 @@ # include // read(), write(), sleep() # include // malloc(), free(), exit(), atoi() +# define INT_MAX 2147483647 +# define INT_MIN -2147483648 typedef struct s_stack { @@ -32,7 +34,7 @@ t_list *launch_algo(t_stack **a, t_stack **b, int i); void print_test(t_list *lst, char *s); void ps_usage(void); void ps_error(int i); -void ps_stop(t_stack *stack, t_list *lst, int i); +void ps_stop(t_list *lst, int i); /* ** algo.c // sort.c @@ -42,7 +44,7 @@ int find_pivot(t_stack *list, int size); int divide_a(t_stack **a, t_stack **b, t_list *solution); int divide_b(t_stack **a, t_stack **b, t_list *solution); void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution); -void hugo_sort(t_stack **a, t_stack **b, t_list *lst); +void hugo_sort(t_stack **a, t_stack **b, t_list *solution); /* ** sort_recursif.c @@ -95,28 +97,28 @@ void print_result(t_list *lst, int i); /* ** swap */ -t_list *sa(t_stack **a, t_list **lst); -t_list *sb(t_stack **b, t_list **lst); -t_list *ss(t_stack **a, t_stack **b, t_list **lst); +t_list *sa(t_stack **a, t_list **solution); +t_list *sb(t_stack **b, t_list **solution); +t_list *ss(t_stack **a, t_stack **b, t_list **solution); /* ** push */ -t_list *pa(t_stack **dst, t_stack **src, t_list **lst); -t_list *pb(t_stack **dst, t_stack **src, t_list **lst); +t_list *pa(t_stack **a, t_stack **b, t_list **solution); +t_list *pb(t_stack **b, t_stack **a, t_list **solution); /* ** rotate */ -t_list *ra(t_stack **stack, t_list **lst); -t_list *rb(t_stack **stack, t_list **lst); -t_list *rr(t_stack **a, t_stack **b, t_list **lst); +t_list *ra(t_stack **a, t_list **solution); +t_list *rb(t_stack **b, t_list **solution); +t_list *rr(t_stack **a, t_stack **b, t_list **solution); /* ** reverse rotate */ -t_list *rra(t_stack **stack, t_list **lst); -t_list *rrb(t_stack **stack, t_list **lst); -t_list *rrr(t_stack **a, t_stack **b, t_list **lst); +t_list *rra(t_stack **a, t_list **solution); +t_list *rrb(t_stack **b, t_list **solution); +t_list *rrr(t_stack **a, t_stack **b, t_list **solution); #endif diff --git a/push_swap b/push_swap index c03bef8..a01a326 100755 Binary files a/push_swap and b/push_swap differ diff --git a/srcs/algo.c b/srcs/algo.c index b59bcac..c425bee 100644 --- a/srcs/algo.c +++ b/srcs/algo.c @@ -102,7 +102,7 @@ void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution) mark_step(solution, "send_sublist_to_a"); } -void recursif_sort(t_stack **a, t_stack **b, t_list *solution) +void hugo_sort(t_stack **a, t_stack **b, t_list *solution) { if (sublist_size(*a) > 4) divide_a(a, b, solution); @@ -119,16 +119,6 @@ void recursif_sort(t_stack **a, t_stack **b, t_list *solution) else return ; } - recursif_sort(a, b, solution); -} - -void hugo_sort(t_stack **a, t_stack **b, t_list *solution) -{ - if (sublist_size(*a) <= 3) - special_sort_3(a, solution); - else if (sublist_size(*a) <= 5) - special_sort_5(a, b, solution); - else - recursif_sort(a, b, solution); + hugo_sort(a, b, solution); } diff --git a/srcs/push_swap.c b/srcs/push_swap.c index 79d8810..e1d41e0 100644 --- a/srcs/push_swap.c +++ b/srcs/push_swap.c @@ -4,7 +4,7 @@ void is_valid(int ac, char **av) { if (ac < 2) - ps_stop(NULL, NULL, 1); + ps_stop(NULL, 1); (void)av; } @@ -28,14 +28,23 @@ int check_flag(int *ac, char ***av) t_stack *fill_stack(t_stack *list, char *nb) { t_stack *new; + long nbl; new = ft_calloc(1, sizeof(t_stack)); if (!new) - ps_stop(NULL, NULL, 2); - new->n = ft_atoi(nb); + ps_stop((t_list *)list, 2); + +/* + if (ft_isnumber(nb) == 0) + ps_stop((t_list *)list, 2); + nbl = ft_atol(nb); + if (nbl < INT_MIN || nbl > INT_MAX) + ps_stop((t_list *)list, 2); + new->n = nbl; new->limit = 0; new->next = list; list = new; +*/ return (list); } @@ -76,8 +85,13 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag) fill_solution(solution, "start"); mark_step(solution, "start"); } - hugo_sort(a, b, solution); -// bubble_sort(a, b, solution); + if (sublist_size(*a) <= 3) + special_sort_3(a, solution); + else if (sublist_size(*a) <= 5) + special_sort_5(a, b, solution); + else + hugo_sort(a, b, solution); +// bubble_sort_luke(a, b, solution); return (solution); } @@ -94,6 +108,6 @@ int main(int ac, char **av) b = NULL; solution = launch_algo(&a, &b, flag); print_result(solution, flag); - ps_stop(NULL, solution, 0); + ps_stop(solution, 0); return (0); } diff --git a/srcs/stop.c b/srcs/stop.c index e8dafe2..bc3e803 100644 --- a/srcs/stop.c +++ b/srcs/stop.c @@ -1,28 +1,27 @@ #include "push_swap.h" -void ps_usage(void) -{ - ft_printf("usage :\n"); - ft_printf("launch executable : ./push_swap [flag -p] nb nb nb nb nb ...\n"); -} - void ps_error(int err) { if (err == 1) - ps_usage(); + ft_printf("usage :\nlaunch executable : ./push_swap [flag -p] nb nb nb nb nb ...\n"); if (err == 2) - ft_printf("error\n"); + ft_putstr_fd("Error\n", 2); exit(0); } -void ps_stop(t_stack *stack, t_list *lst, int err) +/* +** if err < 0, the parameter list is just a t_stack *list +** if err = 0, the list are freed but the program doesn't stop +** if err > 0, a message is printed and the program stop +*/ +void ps_stop(t_list *lst, int err) { t_stack **a; t_stack **b; - if (stack) - ft_lstclear((t_list **)&stack, NULL); - if (lst) + if (err < 0) + ft_lstclear(&lst, NULL); + else if (lst) { a = lst->content; b = lst->next->content; @@ -32,8 +31,6 @@ void ps_stop(t_stack *stack, t_list *lst, int err) lst->next->content = NULL; ft_lstclear(&lst, free); } - if (err < 0) - return ; - else if (err > 0) + if (err > 0) ps_error(err); }