test
This commit is contained in:
parent
70635dd679
commit
a76c4dc406
9
Makefile
9
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
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
chr = (*lst)->next;
|
||||
del((*lst)->content);
|
||||
del((*lst)->nbr);
|
||||
free(*lst);
|
||||
*lst = chr;
|
||||
}
|
||||
|
||||
@ -16,6 +16,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||
{
|
||||
if (!lst)
|
||||
return ;
|
||||
del(lst->content);
|
||||
del(lst->nbr);
|
||||
free(lst);
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
f(lst->nbr);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
48
push_swap.c
48
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 );
|
||||
}
|
||||
@ -17,6 +17,12 @@
|
||||
# include <unistd.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 is_nbr(int nbrarg, char **list);
|
||||
t_list *set_list(int nbrarg, char **list);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user