diff --git a/Utils/indexing.c b/Utils/indexing.c index d95dce0..fc6a040 100644 --- a/Utils/indexing.c +++ b/Utils/indexing.c @@ -60,3 +60,29 @@ t_list *is_double_one(t_list *lst) } return (start); } + +int max_and_sorted(t_list *start) +{ + long long swap; + t_list *lst; + + lst = start; + swap = 0; + while (start) + { + swap = *(long long *)start->nbr; + if (swap > 2147483647 || swap < -2147483648) + { + ft_putstr_fd("Error\n", 2); + ft_lstclear(&start, &free); + return (1); + } + start = start->next; + } + if (is_sorted(lst)) + { + ft_lstclear(&lst, &free); + return (1); + } + return (0); +} diff --git a/Utils/push_swap.c b/Utils/push_swap.c index 0f29b1d..cd52723 100644 --- a/Utils/push_swap.c +++ b/Utils/push_swap.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/25 23:10:37 by apommier #+# #+# */ -/* Updated: 2022/01/19 05:53:41 by apommier ### ########.fr */ +/* Updated: 2022/01/19 18:33:54 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,7 @@ int is_double(int nbrarg, char **list) len = ft_strlen(list[j]); else len = ft_strlen(list[j + i]); - if (ft_strncmp(list[j], list[j + i], len) == 0) + if (ft_strncmp(list[j], list[j + i], len) == 0 || len > 11) return (0); i++; } @@ -79,11 +79,11 @@ int push_swap(int nbrarg, char **list) return (0); } start = set_list(--nbrarg, list); + lst_size = ft_lstsize(start); lst_indexing(start); start = is_double_one(start); - if (!start) + if (!start || max_and_sorted(start)) return (0); - lst_size = ft_lstsize(start); if (lst_size == 1) return (1); if (lst_size == 3 || lst_size == 5) @@ -98,10 +98,10 @@ int push_swap(int nbrarg, char **list) t_list *set_list(int nbrarg, char **src) { - int *tmp; - int i; - int j; - t_list *swap; + long long *tmp; + int i; + int j; + t_list *swap; j = 1; tmp = 0; @@ -112,8 +112,8 @@ t_list *set_list(int nbrarg, char **src) i = 0; while (src[j][i]) { - tmp = ft_calloc(sizeof(int), 1); - *tmp = ft_atoi(&src[j][i]); + tmp = ft_calloc(sizeof(long long), 1); + *tmp = (long long)ft_atoi(&src[j][i]); ft_lstadd_back(&swap, ft_lstnew(tmp)); while ((src[j][i] >= '0' && src[j][i] <= '9') || src[j][i] == '-') i++; diff --git a/Utils/push_swap.h b/Utils/push_swap.h index e31af21..99b743d 100644 --- a/Utils/push_swap.h +++ b/Utils/push_swap.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/25 23:15:17 by apommier #+# #+# */ -/* Updated: 2022/01/19 06:06:31 by apommier ### ########.fr */ +/* Updated: 2022/01/19 18:38:00 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,7 @@ t_list *set_list(int nbrarg, char **list); void lst_indexing(t_list *list); int is_double(int nbrarg, char **list); t_list *is_double_one(t_list *lst); +int max_and_sorted(t_list *start); t_list *find_loop_index(t_list *list); int find_loop(t_list *start, t_list *list, int setswap); t_list *ft_lstnew(void *content); @@ -89,6 +90,4 @@ int do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete); t_slist *verify_list(t_slist *a); void big_slstclear(t_slist **lst); -void printf_llist(t_list *start); - #endif \ No newline at end of file diff --git a/Utils/sort_little.c b/Utils/sort_little.c index 28da437..b35ce70 100644 --- a/Utils/sort_little.c +++ b/Utils/sort_little.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/18 03:31:31 by apommier #+# #+# */ -/* Updated: 2022/01/19 06:03:44 by apommier ### ########.fr */ +/* Updated: 2022/01/19 18:33:33 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,7 @@ void sort_little(t_list *list) list = turn_list(list, action); printf_slist(action); s_lstclear(&action); + ft_lstclear(&list, &free); } t_list *sort3(t_list *a, t_slist **action)