diff --git a/Makefile b/Makefile index d8071d0..80bd54f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/11/13 13:06:47 by apommier #+# #+# # -# Updated: 2022/01/19 03:50:25 by apommier ### ########.fr # +# Updated: 2022/01/19 05:41:28 by apommier ### ########.fr # # # # **************************************************************************** # @@ -42,7 +42,7 @@ LIBFT = ./libft ${NAME}:${OBJS} make bonus -C ${LIBFT} - gcc -g ${OBJS} ${LIBFT}/libft.a + gcc -g ${OBJS} ${LIBFT}/libft.a mv a.out push_swap bonus:${BONUS_O} diff --git a/Utils/indexing.c b/Utils/indexing.c index 47de8a0..d95dce0 100644 --- a/Utils/indexing.c +++ b/Utils/indexing.c @@ -35,3 +35,28 @@ void lst_indexing(t_list *list) save = save->next; } } + +t_list *is_double_one(t_list *lst) +{ + t_list *start; + t_list *swap; + + start = lst; + swap = 0; + while (lst) + { + swap = lst->next; + while (swap) + { + if (*(int *)lst->nbr == *(int *)swap->nbr) + { + ft_putstr_fd("Error\n", 2); + ft_lstclear(&start, &free); + return (0); + } + swap = swap->next; + } + lst = lst->next; + } + return (start); +} diff --git a/Utils/push_swap.c b/Utils/push_swap.c index 3ea2f45..0f29b1d 100644 --- a/Utils/push_swap.c +++ b/Utils/push_swap.c @@ -6,18 +6,16 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/25 23:10:37 by apommier #+# #+# */ -/* Updated: 2022/01/18 06:08:53 by apommier ### ########.fr */ +/* Updated: 2022/01/19 05:53:41 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -int is_nbr(int nbrarg, char **list) +int is_nbr(int nbrarg, char **list, int i) { - int i; int j; - i = 0; j = 0; while (--nbrarg) { @@ -29,12 +27,14 @@ int is_nbr(int nbrarg, char **list) i++; if (list[j][i] == '-' || (list[j][i] == '+')) i++; - if (list[j][i] && (list[j][i] < '0' || list[j][i] > '9')) + if (!list[j][i] && (list[j][i] < '0' || list[j][i] > '9')) return (0); while (list[j][i] && list[j][i] >= '0' && list[j][i] <= '9') i++; if (list[j][i] && list[j][i] != ' ') return (0); + while (list[j][i] == ' ') + i++; } } return (1); @@ -73,27 +73,30 @@ int push_swap(int nbrarg, char **list) int lst_size; start = 0; - if (!is_nbr(nbrarg, list) || !is_double(nbrarg, list)) + if (!is_nbr(nbrarg, list, 0) || !is_double(nbrarg, list)) { ft_putstr_fd("Error\n", 2); return (0); } start = set_list(--nbrarg, list); + lst_indexing(start); + start = is_double_one(start); + if (!start) + return (0); lst_size = ft_lstsize(start); if (lst_size == 1) return (1); - lst_indexing(start); if (lst_size == 3 || lst_size == 5) - { sort_little(start); - return (1); + else + { + start = find_loop_index(start); + ft_lstclear(&start, &free); } - start = find_loop_index(start); - ft_lstclear(&start, &free); return (1); } -t_list *set_list(int nbrarg, char **srcs) +t_list *set_list(int nbrarg, char **src) { int *tmp; int i; @@ -107,14 +110,14 @@ t_list *set_list(int nbrarg, char **srcs) while (nbrarg--) { i = 0; - while (srcs[j][i]) - { + while (src[j][i]) + { tmp = ft_calloc(sizeof(int), 1); - *tmp = ft_atoi(&srcs[j][i]); + *tmp = ft_atoi(&src[j][i]); ft_lstadd_back(&swap, ft_lstnew(tmp)); - while (srcs[j][i] == ' ') + while ((src[j][i] >= '0' && src[j][i] <= '9') || src[j][i] == '-') i++; - while (srcs[j][i] && srcs[j][i] != ' ') + while (src[j][i] == ' ') i++; } j++; diff --git a/Utils/push_swap.h b/Utils/push_swap.h index 515d243..e31af21 100644 --- a/Utils/push_swap.h +++ b/Utils/push_swap.h @@ -6,14 +6,13 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/11/25 23:15:17 by apommier #+# #+# */ -/* Updated: 2022/01/19 03:53:31 by apommier ### ########.fr */ +/* Updated: 2022/01/19 06:06:31 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PUSH_SWAP_H # define PUSH_SWAP_H -# include # include # include "../libft/libft.h" # include "../libft/get_next_line.h" @@ -25,10 +24,11 @@ typedef struct procest_slist } t_slist; int push_swap(int nbrarg, char **list); -int is_nbr(int nbrarg, char **list); +int is_nbr(int nbrarg, char **list, int i); 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); 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); diff --git a/Utils/sort_little.c b/Utils/sort_little.c index 87b3d51..28da437 100644 --- a/Utils/sort_little.c +++ b/Utils/sort_little.c @@ -6,33 +6,12 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/18 03:31:31 by apommier #+# #+# */ -/* Updated: 2022/01/19 03:32:05 by apommier ### ########.fr */ +/* Updated: 2022/01/19 06:03:44 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" -//t_list *end_sort3(t_list *list, t_slist **action); -//{ - -//} - -void printf_llist(t_list *start) -{ - int i; - - i = 0; - printf("----printf_list----\n"); - while (start) - { - i++; - printf("lst%d--nbr:%d indx: %d\n", i,*(int *)start->nbr, start->index); - start = start->next; - } - printf("----end_print----"); - return ; -} - void sort_little(t_list *list) { t_slist *action; diff --git a/checker_folder/checker_utils.c b/checker_folder/checker_utils.c index 39a345e..f8f268e 100644 --- a/checker_folder/checker_utils.c +++ b/checker_folder/checker_utils.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/18 02:14:22 by apommier #+# #+# */ -/* Updated: 2022/01/19 03:42:58 by apommier ### ########.fr */ +/* Updated: 2022/01/19 06:10:06 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,5 +28,6 @@ int do_move2(t_list **lst, t_list **lst_b, t_slist *a, t_slist **delete) if (!rra_rrb(lst_b, delete, 'a')) return (0); } + s_lstclear(delete); return (1); } diff --git a/checker_folder/main.c b/checker_folder/main.c index cbc0dfe..adfd526 100644 --- a/checker_folder/main.c +++ b/checker_folder/main.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/17 21:29:45 by apommier #+# #+# */ -/* Updated: 2022/01/19 03:44:06 by apommier ### ########.fr */ +/* Updated: 2022/01/19 06:07:41 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ t_slist *verify_list(t_slist *a) return (start); } -int do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete) +int do_move(t_list **lst, t_list **lst_b, t_slist *a, t_slist *delete) { if (!ft_strcmp("pa\n", a) && !pa(lst, lst_b, &delete)) return (0); @@ -104,7 +104,7 @@ int main(int argc, char **argv) start_action = 0; if (argc == 1) return (1); - if (!is_nbr(argc, argv) || !is_double(argc, argv)) + if (!is_nbr(argc, argv, 0) || !is_double(argc, argv)) { ft_putstr_fd("Error\n", 2); return (0);