diff --git a/Makefile b/Makefile index 3288bfc..584cc2c 100644 --- a/Makefile +++ b/Makefile @@ -19,19 +19,20 @@ CFLAGS = -Wall -Wextra RM = rm -rf LIBFT = ./libft -.c.o: - gcc ${CFLAGS} -c $< -o ${<:.c=.o} - ${NAME}:${OBJS} make bonus -C ${LIBFT} - + gcc ${CFLAGS} ${OBJS} ${LIBFT}/libft.a + mv a.out push_swap + all: ${NAME} clean: ${RM} ${OBJS} + make clean -C ${LIBFT} fclean: clean ${RM} ${NAME} + make fclean -C ${LIBFT} re: fclean all diff --git a/checker_linux b/checker_linux new file mode 100644 index 0000000..002d593 Binary files /dev/null and b/checker_linux differ diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c index d768b5a..4aa7802 100644 --- a/libft/ft_lstclear.c +++ b/libft/ft_lstclear.c @@ -20,7 +20,7 @@ void ft_lstclear(t_list **lst, void (*del)(void*)) while (*lst) { chr = (*lst)->next; - del((*lst)->content); + del((*lst)->nbr); free(*lst); *lst = chr; } diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c index d932649..f0dea04 100644 --- a/libft/ft_lstdelone.c +++ b/libft/ft_lstdelone.c @@ -16,6 +16,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*)) { if (!lst) return ; - del(lst->content); + del(lst->nbr); free(lst); } diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c index e3ac84f..0e9ea7a 100644 --- a/libft/ft_lstiter.c +++ b/libft/ft_lstiter.c @@ -16,7 +16,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *)) { while (lst) { - f(lst->content); + f(lst->nbr); lst = lst->next; } } diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c index d53c442..252c0c6 100644 --- a/libft/ft_lstmap.c +++ b/libft/ft_lstmap.c @@ -20,7 +20,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) begin = 0; while (lst) { - new = ft_lstnew(f(lst->content)); + new = ft_lstnew(f(lst->nbr)); if (!new) { ft_lstclear(&begin, *del); diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c index 9a162bd..7dcf87d 100644 --- a/libft/ft_lstnew.c +++ b/libft/ft_lstnew.c @@ -19,7 +19,7 @@ t_list *ft_lstnew(void *content) new = (t_list*)malloc(sizeof(t_list)); if (!new) return (0); - new->content = content; + new->nbr = content; new->next = 0; return (new); } diff --git a/push_swap.c b/push_swap.c index bb45b0b..207397b 100644 --- a/push_swap.c +++ b/push_swap.c @@ -15,22 +15,31 @@ int is_nbr(int nbrarg, char **list) { int i; - char *save; + int j; - save = *list; i = 0; - while (nbrarg) - { + j = 0; + printf("test\n"); + + while (++j < nbrarg) + { + printf("string= %s\n", list[j]); + printf("j1= %d\n", j); i = 0; - save++; - while (save[i]) + if (list[j][i] == '-' && !list[j][i++]) + return (0); + while (list[j][i]) { - if ((save[i] < '0' || save[i] > '9') && save[i] != '-') + if (list[j][i] < '0' || list[j][i] > '9') + { + printf("0000\n"); return (0); + } + printf("char = %c\n", list[j][i]); i++; } - nbrarg--; } + return (1); } @@ -49,7 +58,9 @@ int is_double(int nbrarg, char **list) { i++; if (ft_strncmp(save + j, save + j + i, ft_strlen(save)) == 0) + { return (0); + } } j++; i = 0; @@ -62,12 +73,21 @@ int push_swap(int nbrarg, char **list) t_list *start; start = 0; - if (!is_nbr(nbrarg++, list) || !is_double(nbrarg++, list)) + if (!is_nbr(nbrarg, list)) { ft_putstr_fd("Error\n", 2); return (0); } + else + { + printf("done"); + return(1); + } start = set_list(nbrarg++, list); + if (is_sorted(*list)) + return (1); + else + choose_algo(start); return (1); } @@ -90,7 +110,7 @@ int is_sorted(t_list *list) { while (list->next) { - if (list->content > list->next->content) + if (list->nbr > list->next->nbr) return (0); else list = list->next; @@ -98,3 +118,11 @@ int is_sorted(t_list *list) return (1); } +choose_algo(t_list *list) +{ + int size; + + size = lst_size(list); + if (size == 3) + sort3(list ); +} \ No newline at end of file diff --git a/push_swap.h b/push_swap.h index d41e2ce..97bec83 100644 --- a/push_swap.h +++ b/push_swap.h @@ -17,6 +17,12 @@ # include # include "./libft/libft.h" +typedef struct action_list +{ + void *action; + struct action_list *next; +} action_list; + int push_swap(int nbrarg, char **list); int is_nbr(int nbrarg, char **list); t_list *set_list(int nbrarg, char **list);