test
This commit is contained in:
parent
70635dd679
commit
a76c4dc406
9
Makefile
9
Makefile
@ -19,19 +19,20 @@ CFLAGS = -Wall -Wextra
|
|||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
LIBFT = ./libft
|
LIBFT = ./libft
|
||||||
|
|
||||||
.c.o:
|
|
||||||
gcc ${CFLAGS} -c $< -o ${<:.c=.o}
|
|
||||||
|
|
||||||
${NAME}:${OBJS}
|
${NAME}:${OBJS}
|
||||||
make bonus -C ${LIBFT}
|
make bonus -C ${LIBFT}
|
||||||
|
gcc ${CFLAGS} ${OBJS} ${LIBFT}/libft.a
|
||||||
|
mv a.out push_swap
|
||||||
|
|
||||||
all: ${NAME}
|
all: ${NAME}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
${RM} ${OBJS}
|
${RM} ${OBJS}
|
||||||
|
make clean -C ${LIBFT}
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
${RM} ${NAME}
|
${RM} ${NAME}
|
||||||
|
make fclean -C ${LIBFT}
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
|||||||
BIN
checker_linux
Normal file
BIN
checker_linux
Normal file
Binary file not shown.
@ -20,7 +20,7 @@ void ft_lstclear(t_list **lst, void (*del)(void*))
|
|||||||
while (*lst)
|
while (*lst)
|
||||||
{
|
{
|
||||||
chr = (*lst)->next;
|
chr = (*lst)->next;
|
||||||
del((*lst)->content);
|
del((*lst)->nbr);
|
||||||
free(*lst);
|
free(*lst);
|
||||||
*lst = chr;
|
*lst = chr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*))
|
|||||||
{
|
{
|
||||||
if (!lst)
|
if (!lst)
|
||||||
return ;
|
return ;
|
||||||
del(lst->content);
|
del(lst->nbr);
|
||||||
free(lst);
|
free(lst);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *))
|
|||||||
{
|
{
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
f(lst->content);
|
f(lst->nbr);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
|||||||
begin = 0;
|
begin = 0;
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
new = ft_lstnew(f(lst->content));
|
new = ft_lstnew(f(lst->nbr));
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
ft_lstclear(&begin, *del);
|
ft_lstclear(&begin, *del);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ t_list *ft_lstnew(void *content)
|
|||||||
new = (t_list*)malloc(sizeof(t_list));
|
new = (t_list*)malloc(sizeof(t_list));
|
||||||
if (!new)
|
if (!new)
|
||||||
return (0);
|
return (0);
|
||||||
new->content = content;
|
new->nbr = content;
|
||||||
new->next = 0;
|
new->next = 0;
|
||||||
return (new);
|
return (new);
|
||||||
}
|
}
|
||||||
|
|||||||
48
push_swap.c
48
push_swap.c
@ -15,22 +15,31 @@
|
|||||||
int is_nbr(int nbrarg, char **list)
|
int is_nbr(int nbrarg, char **list)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *save;
|
int j;
|
||||||
|
|
||||||
save = *list;
|
|
||||||
i = 0;
|
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;
|
i = 0;
|
||||||
save++;
|
if (list[j][i] == '-' && !list[j][i++])
|
||||||
while (save[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);
|
return (0);
|
||||||
|
}
|
||||||
|
printf("char = %c\n", list[j][i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
nbrarg--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +58,9 @@ int is_double(int nbrarg, char **list)
|
|||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
if (ft_strncmp(save + j, save + j + i, ft_strlen(save)) == 0)
|
if (ft_strncmp(save + j, save + j + i, ft_strlen(save)) == 0)
|
||||||
|
{
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -62,12 +73,21 @@ int push_swap(int nbrarg, char **list)
|
|||||||
t_list *start;
|
t_list *start;
|
||||||
|
|
||||||
start = 0;
|
start = 0;
|
||||||
if (!is_nbr(nbrarg++, list) || !is_double(nbrarg++, list))
|
if (!is_nbr(nbrarg, list))
|
||||||
{
|
{
|
||||||
ft_putstr_fd("Error\n", 2);
|
ft_putstr_fd("Error\n", 2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("done");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
start = set_list(nbrarg++, list);
|
start = set_list(nbrarg++, list);
|
||||||
|
if (is_sorted(*list))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
choose_algo(start);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +110,7 @@ int is_sorted(t_list *list)
|
|||||||
{
|
{
|
||||||
while (list->next)
|
while (list->next)
|
||||||
{
|
{
|
||||||
if (list->content > list->next->content)
|
if (list->nbr > list->next->nbr)
|
||||||
return (0);
|
return (0);
|
||||||
else
|
else
|
||||||
list = list->next;
|
list = list->next;
|
||||||
@ -98,3 +118,11 @@ int is_sorted(t_list *list)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
choose_algo(t_list *list)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = lst_size(list);
|
||||||
|
if (size == 3)
|
||||||
|
sort3(list );
|
||||||
|
}
|
||||||
@ -17,6 +17,12 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "./libft/libft.h"
|
# include "./libft/libft.h"
|
||||||
|
|
||||||
|
typedef struct action_list
|
||||||
|
{
|
||||||
|
void *action;
|
||||||
|
struct action_list *next;
|
||||||
|
} action_list;
|
||||||
|
|
||||||
int push_swap(int nbrarg, char **list);
|
int push_swap(int nbrarg, char **list);
|
||||||
int is_nbr(int nbrarg, char **list);
|
int is_nbr(int nbrarg, char **list);
|
||||||
t_list *set_list(int nbrarg, char **list);
|
t_list *set_list(int nbrarg, char **list);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user