test
This commit is contained in:
parent
a76c4dc406
commit
c582aec0ba
13
Makefile
13
Makefile
@ -6,22 +6,27 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/11/13 13:06:47 by apommier #+# #+# #
|
||||
# Updated: 2021/11/25 23:57:06 by apommier ### ########.fr #
|
||||
# Updated: 2022/01/06 23:59:23 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = push_swap
|
||||
SRCS = push_swap.c \
|
||||
process.c\
|
||||
main.c
|
||||
main.c\
|
||||
indexing.c
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
CFLAGS = -Wall -Wextra
|
||||
CFLAGS =
|
||||
RM = rm -rf
|
||||
LIBFT = ./libft
|
||||
|
||||
2:${OBJS}
|
||||
gcc -g ${CFLAGS} ${OBJS} ${LIBFT}/libft.a
|
||||
mv a.out push_swap
|
||||
|
||||
${NAME}:${OBJS}
|
||||
make bonus -C ${LIBFT}
|
||||
gcc ${CFLAGS} ${OBJS} ${LIBFT}/libft.a
|
||||
gcc -g ${CFLAGS} ${OBJS} ${LIBFT}/libft.a
|
||||
mv a.out push_swap
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:15:23 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/07 17:55:06 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:46:20 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/06 01:35:14 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 15:43:19 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/07 17:55:25 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
typedef struct s_list
|
||||
{
|
||||
void *nbr;
|
||||
int index;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
|
||||
11
process.c
11
process.c
@ -12,7 +12,7 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ft_sa_sb(t_list **list, t_list **process, char *type)
|
||||
void ft_sa_sb(t_list **list, t_list **process, char type)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
@ -22,7 +22,7 @@ void ft_sa_sb(t_list **list, t_list **process, char *type)
|
||||
(*list)->next->next = swap;
|
||||
}
|
||||
|
||||
void ft_ra_rb(t_list **list, t_list **process, char *type)
|
||||
void ft_ra_rb(t_list **list, t_list **process, char type)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
@ -49,3 +49,10 @@ void ft_pb(t_list **list_a, t_list **list_b, t_list **process)
|
||||
*list_a = (*list_a)->next;
|
||||
ft_lstadd_front(list_b, swap);
|
||||
}
|
||||
|
||||
void ft_rra_rrb(t_list **list, t_list **process, char type)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
swap = *list;
|
||||
}
|
||||
|
||||
92
push_swap.c
92
push_swap.c
@ -6,12 +6,26 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:10:37 by apommier #+# #+# */
|
||||
/* Updated: 2021/11/26 00:00:53 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/07 18:57:42 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void printf_list(t_list *start)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
printf("----printf_list----\n");
|
||||
while(start)
|
||||
{
|
||||
i++;
|
||||
printf("lst%d --- nbr: %d index: %d\n", i,*(int*)start->nbr, start->index);
|
||||
start = start->next;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int is_nbr(int nbrarg, char **list)
|
||||
{
|
||||
int i;
|
||||
@ -19,12 +33,8 @@ int is_nbr(int nbrarg, char **list)
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
printf("test\n");
|
||||
|
||||
while (++j < nbrarg)
|
||||
{
|
||||
printf("string= %s\n", list[j]);
|
||||
printf("j1= %d\n", j);
|
||||
i = 0;
|
||||
if (list[j][i] == '-' && !list[j][i++])
|
||||
return (0);
|
||||
@ -32,10 +42,8 @@ int is_nbr(int nbrarg, char **list)
|
||||
{
|
||||
if (list[j][i] < '0' || list[j][i] > '9')
|
||||
{
|
||||
printf("0000\n");
|
||||
return (0);
|
||||
}
|
||||
printf("char = %c\n", list[j][i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -47,23 +55,25 @@ int is_double(int nbrarg, char **list)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *save;
|
||||
int len;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
save = *list + 1;
|
||||
while (save + j + 1)
|
||||
i = 1;
|
||||
j = 1;
|
||||
nbrarg--;
|
||||
while (nbrarg - j)
|
||||
{
|
||||
while (j + i + save)
|
||||
{
|
||||
i++;
|
||||
if (ft_strncmp(save + j, save + j + i, ft_strlen(save)) == 0)
|
||||
i = 1;
|
||||
while(list[j + i])
|
||||
{
|
||||
if (ft_strlen(list[j]) > ft_strlen(list[j + i]))
|
||||
len = ft_strlen(list[j]);
|
||||
else
|
||||
len = ft_strlen(list[j + i]);
|
||||
if (ft_strncmp(list[j], list[j + i], len) == 0)
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
i = 0;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
@ -73,44 +83,52 @@ int push_swap(int nbrarg, char **list)
|
||||
t_list *start;
|
||||
|
||||
start = 0;
|
||||
if (!is_nbr(nbrarg, list))
|
||||
if (!is_nbr(nbrarg, list) || !is_double(nbrarg, list))
|
||||
{
|
||||
ft_putstr_fd("Error\n", 2);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
start = set_list(--nbrarg, list);
|
||||
lst_indexing(start);
|
||||
printf_list(start);
|
||||
if (is_sorted(start))
|
||||
{
|
||||
printf("done");
|
||||
ft_lstclear(&start, &free);
|
||||
return (1);
|
||||
}
|
||||
start = set_list(nbrarg++, list);
|
||||
if (is_sorted(*list))
|
||||
return (1);
|
||||
else
|
||||
choose_algo(start);
|
||||
ft_lstclear(&start, &free);
|
||||
return (1);
|
||||
}
|
||||
|
||||
t_list *set_list(int nbrarg, char **list)
|
||||
t_list *set_list(int nbrarg, char **srcs)
|
||||
{
|
||||
int *tmp;
|
||||
t_list *start;
|
||||
t_list *swap;
|
||||
|
||||
(*list)++;
|
||||
start = ft_lstnew(*list);
|
||||
while (nbrarg)
|
||||
start = 0;
|
||||
swap = 0;
|
||||
*(srcs)++;
|
||||
tmp = ft_calloc(sizeof(int), 1);
|
||||
*tmp = ft_atoi(*srcs);
|
||||
start = ft_lstnew(tmp);
|
||||
swap = start;
|
||||
while (--nbrarg)
|
||||
{
|
||||
(*list)++;
|
||||
ft_lstadd_back(&start, ft_lstnew(*list));
|
||||
*(srcs)++;
|
||||
tmp = ft_calloc(sizeof(int), 1);
|
||||
*tmp = ft_atoi(*srcs);
|
||||
swap->next = ft_lstnew(tmp);
|
||||
swap = swap->next;
|
||||
}
|
||||
return (start);
|
||||
}
|
||||
|
||||
|
||||
int is_sorted(t_list *list)
|
||||
{
|
||||
while (list->next)
|
||||
{
|
||||
if (list->nbr > list->next->nbr)
|
||||
if (*(int*)list->nbr > *(int*)list->next->nbr)
|
||||
return (0);
|
||||
else
|
||||
list = list->next;
|
||||
@ -118,11 +136,11 @@ int is_sorted(t_list *list)
|
||||
return (1);
|
||||
}
|
||||
|
||||
choose_algo(t_list *list)
|
||||
/*void choose_algo(t_list *list)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = lst_size(list);
|
||||
size = ft_lstsize(list);
|
||||
if (size == 3)
|
||||
sort3(list);
|
||||
}
|
||||
}*/
|
||||
14
push_swap.h
14
push_swap.h
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:15:17 by apommier #+# #+# */
|
||||
/* Updated: 2021/11/25 23:48:20 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/06 04:38:07 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,15 +17,21 @@
|
||||
# include <unistd.h>
|
||||
# include "./libft/libft.h"
|
||||
|
||||
typedef struct action_list
|
||||
/*typedef struct process_list
|
||||
{
|
||||
void *action;
|
||||
struct action_list *next;
|
||||
} action_list;
|
||||
struct process_list *next;
|
||||
} action_list;*/
|
||||
|
||||
void sort3(t_list *list);
|
||||
int push_swap(int nbrarg, char **list);
|
||||
int is_nbr(int nbrarg, char **list);
|
||||
t_list *set_list(int nbrarg, char **list);
|
||||
void lst_indexing(t_list *list);
|
||||
int is_double(int nbrarg, char **list);
|
||||
int is_sorted(t_list *list);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
23
sort3.c
23
sort3.c
@ -14,9 +14,28 @@
|
||||
|
||||
void sort3(t_list *list)
|
||||
{
|
||||
if (list->nbr < list->next->nbr && list->nbr < list->next->next->nbr)
|
||||
{
|
||||
ft_sa_sb(&list, process, 'a');
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
}
|
||||
if (list->nbr > list->next->nbr && list->nbr > list->next->next->nbr)
|
||||
{
|
||||
if (list->next->nbr < list->next->next->nbr)
|
||||
|
||||
if (list->next->nbr > list->next->next->nbr)
|
||||
{
|
||||
ft_sa_sb(&list, process, 'a');
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
}
|
||||
else
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
}
|
||||
if (list->nbr > list->next->nbr && list->nbr < list->next->next->nbr)
|
||||
ft_sa_sb(&list, process, 'a');
|
||||
if (list->nbr < list->next->nbr && list->next->next->nbr)
|
||||
{
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
ft_ra_rb(&list, process, 'a');
|
||||
}
|
||||
return ;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user