done
This commit is contained in:
parent
597e1834e3
commit
772733d41e
8
Makefile
8
Makefile
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/11/13 13:06:47 by apommier #+# #+# #
|
||||
# Updated: 2022/01/14 20:19:54 by apommier ### ########.fr #
|
||||
# Updated: 2022/01/17 14:08:51 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -15,11 +15,13 @@ SRCS = push_swap.c \
|
||||
process.c\
|
||||
main.c\
|
||||
sorting.c\
|
||||
s_list.c\
|
||||
t_slist.c\
|
||||
set_a.c\
|
||||
optimise_move.c\
|
||||
optimise_move2.c\
|
||||
indexing.c
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
CFLAGS =
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
LIBFT = ./libft
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ SRCS = ft_memset.c \
|
||||
ft_calloc.c \
|
||||
ft_strdup.c \
|
||||
ft_substr.c \
|
||||
ft_strjoin.c \
|
||||
ft_strtrim.c \
|
||||
ft_split.c \
|
||||
ft_itoa.c \
|
||||
@ -38,7 +37,7 @@ BONUS_C = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back
|
||||
ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c ft_lstbeforelast.c
|
||||
BONUS_O = ${BONUS_C:.c=.o}
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra
|
||||
RM = rm -rf
|
||||
|
||||
.c.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:17 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 12:05:13 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:24:37 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:48 by apommier #+# #+# */
|
||||
/* Updated: 2020/11/29 17:02:33 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:26:30 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:57 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 16:13:27 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:27:24 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,6 +19,8 @@ void *ft_calloc(size_t nmemb, size_t size)
|
||||
|
||||
i = 0;
|
||||
new = malloc(size * nmemb);
|
||||
if (!new)
|
||||
return (0);
|
||||
if (new)
|
||||
{
|
||||
while (size * nmemb - i)
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 18:20:19 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/20 11:52:40 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:28:01 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/12/09 19:16:55 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/13 19:00:16 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:28:22 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/07 17:55:06 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:28:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/15 23:45:37 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:29:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:04 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 14:07:04 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:29:38 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:39 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 13:53:45 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:29:51 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:51 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 14:14:51 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:30:32 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:03 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 16:14:24 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:30:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:14 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/13 21:15:13 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:31:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:24 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 15:48:06 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:31:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 23:25:57 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:42:09 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:31:56 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/07 00:54:12 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/13 23:07:09 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:34:08 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -71,7 +71,8 @@ char **ft_split(char const *s, char c)
|
||||
while (s[i] == c && s[i])
|
||||
i++;
|
||||
}
|
||||
if (!(dest = (char**)malloc(sizeof(char*) * (i + j))))
|
||||
dest = (char **)malloc(sizeof(char *) * (i + j));
|
||||
if (!dest)
|
||||
return (0);
|
||||
dest[j] = 0;
|
||||
call((char *)s, c, dest, j);
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/12 13:57:59 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 13:58:05 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:34:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/11 15:38:13 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 17:00:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
if (!(dest = (char*)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
|
||||
return (0);
|
||||
while (s1[i] && s1)
|
||||
{
|
||||
dest[j] = s1[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2[i] && s2)
|
||||
{
|
||||
dest[j] = s2[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
dest[j] = 0;
|
||||
return (dest);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:07 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 16:07:05 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:38:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:19 by apommier #+# #+# */
|
||||
/* Updated: 2020/11/29 17:12:23 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:38:56 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 19:03:09 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 16:52:49 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:39:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:31 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/13 20:44:39 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:39:13 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:42 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/13 22:55:27 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:39:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:52 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 16:14:41 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:39:37 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 23:52:05 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 18:06:01 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:40:17 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,7 +57,8 @@ char *ft_strtrim(char const *s1, char const *set)
|
||||
if (!s1)
|
||||
return (0);
|
||||
len = len_dest(s1, set);
|
||||
if (!(dest = ft_calloc(len + 1, 1)))
|
||||
dest = ft_calloc(len + 1, 1);
|
||||
if (!dest)
|
||||
return (0);
|
||||
while (is_set(set, s1[i]))
|
||||
i++;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/13 18:56:56 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 15:47:21 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
typedef struct s_list
|
||||
typedef struct t_slist
|
||||
{
|
||||
void *nbr;
|
||||
int index;
|
||||
int swap;
|
||||
struct s_list *next;
|
||||
struct t_slist *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
@ -50,7 +50,6 @@ void *ft_calloc(size_t nmenb, size_t size);
|
||||
char *ft_strdup(const char *s);
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
|
||||
2
main.c
2
main.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:15:43 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/15 20:51:55 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 11:46:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
124
optimise_move.c
Normal file
124
optimise_move.c
Normal file
@ -0,0 +1,124 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* optimise_move.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/15 23:50:43 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 14:09:26 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include"push_swap.h"
|
||||
|
||||
int ft_strcmp(const char *s1, t_slist *str)
|
||||
{
|
||||
int i;
|
||||
char *s2;
|
||||
|
||||
if (!str)
|
||||
return (1);
|
||||
s2 = (char *)str->action;
|
||||
i = 0;
|
||||
if (s2)
|
||||
{
|
||||
while (s1[i] || s2[i])
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
{
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void cut_lst(t_slist *lst)
|
||||
{
|
||||
t_slist *save;
|
||||
|
||||
save = 0;
|
||||
if (!lst)
|
||||
return ;
|
||||
if (lst->next)
|
||||
{
|
||||
save = lst->next->next;
|
||||
lst->next->next = 0;
|
||||
if (lst->next)
|
||||
free(lst->next);
|
||||
lst->next = save;
|
||||
}
|
||||
}
|
||||
|
||||
t_slist *transform_list(t_slist *start, t_slist *start2, int r1, int r2)
|
||||
{
|
||||
t_slist *type;
|
||||
|
||||
type = start;
|
||||
if (r2 < r1)
|
||||
{
|
||||
while (r2--)
|
||||
{
|
||||
cut_lst(start2);
|
||||
start->action = "rr";
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (r1--)
|
||||
{
|
||||
cut_lst(start2);
|
||||
start->action = "rr";
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
return (type);
|
||||
}
|
||||
|
||||
t_slist *sequence(t_slist *lst, t_slist *start1, t_slist *start2, int r1)
|
||||
{
|
||||
char *type;
|
||||
int r2;
|
||||
|
||||
type = 0;
|
||||
r2 = 0;
|
||||
if (!ft_strcmp("ra", lst) || !ft_strcmp("rb", lst))
|
||||
{
|
||||
type = lst->action;
|
||||
while (!ft_strcmp(type, lst) && r2++ >= 0)
|
||||
lst = lst->next;
|
||||
lst = transform_list(start1, start2, r1, r2);
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
|
||||
void optimise_move(t_slist **action, t_slist *start2, int r1)
|
||||
{
|
||||
t_slist *start1;
|
||||
t_slist *lst;
|
||||
char *type;
|
||||
|
||||
type = 0;
|
||||
lst = *action;
|
||||
while (lst)
|
||||
{
|
||||
r1 = 0;
|
||||
if (!ft_strcmp("ra", lst) || !ft_strcmp("rb", lst))
|
||||
{
|
||||
start1 = lst;
|
||||
type = lst->action;
|
||||
while (!ft_strcmp(type, lst) && r1++ >= 0)
|
||||
{
|
||||
start2 = lst;
|
||||
lst = lst->next;
|
||||
}
|
||||
lst = sequence(lst, start1, start2, r1);
|
||||
}
|
||||
else if (lst)
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
83
optimise_move2.c
Normal file
83
optimise_move2.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* optimise_move2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/17 07:44:45 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 14:16:41 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_slist *transform_list2(t_slist *start, t_slist *start2, int r1, int r2)
|
||||
{
|
||||
t_slist *type;
|
||||
|
||||
type = start;
|
||||
if (r2 < r1)
|
||||
{
|
||||
while (r2--)
|
||||
{
|
||||
cut_lst(start2);
|
||||
start->action = "rrr";
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (r1--)
|
||||
{
|
||||
cut_lst(start2);
|
||||
start->action = "rrr";
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
return (type);
|
||||
}
|
||||
|
||||
t_slist *sequence2(t_slist *lst, t_slist *start1, t_slist *start2, int r1)
|
||||
{
|
||||
char *type;
|
||||
int r2;
|
||||
|
||||
type = 0;
|
||||
r2 = 0;
|
||||
if (!ft_strcmp("rra", lst) || !ft_strcmp("rrb", lst))
|
||||
{
|
||||
type = lst->action;
|
||||
while (!ft_strcmp(type, lst) && r2++ >= 0)
|
||||
lst = lst->next;
|
||||
lst = transform_list2(start1, start2, r1, r2);
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
|
||||
void optimise_move2(t_slist **action, t_slist *start2, int r1)
|
||||
{
|
||||
t_slist *start1;
|
||||
t_slist *lst;
|
||||
char *type;
|
||||
|
||||
type = 0;
|
||||
lst = *action;
|
||||
while (lst)
|
||||
{
|
||||
r1 = 0;
|
||||
if (!ft_strcmp("rra", lst) || !ft_strcmp("rrb", lst))
|
||||
{
|
||||
start1 = lst;
|
||||
type = lst->action;
|
||||
while (!ft_strcmp(type, lst) && r1++ >= 0)
|
||||
{
|
||||
start2 = lst;
|
||||
lst = lst->next;
|
||||
}
|
||||
lst = sequence2(lst, start1, start2, r1);
|
||||
}
|
||||
else if (lst)
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
30
process.c
30
process.c
@ -5,14 +5,14 @@
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:15:09 by apommier #+# #+# */
|
||||
/* Updated: 2021/11/25 23:15:09 by apommier ### ########.fr */
|
||||
/* Created: 2022/01/17 11:52:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:52:37 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *ft_sa_sb(t_list **list, s_list **process, char type, int set)
|
||||
void ft_sa_sb(t_list **list, t_slist **process, char type, int set)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
@ -23,13 +23,13 @@ t_list *ft_sa_sb(t_list **list, s_list **process, char type, int set)
|
||||
if (set)
|
||||
{
|
||||
if (type == 'a')
|
||||
s_lstadd_back(process, new_slist("sa\n"));
|
||||
s_lstadd_back(process, new_slist("sa"));
|
||||
else if (type == 'b')
|
||||
s_lstadd_back(process, new_slist("sb\n"));
|
||||
s_lstadd_back(process, new_slist("sb"));
|
||||
}
|
||||
}
|
||||
|
||||
t_list *ft_ra_rb(t_list **list, s_list **process, char type)
|
||||
void ft_ra_rb(t_list **list, t_slist **process, char type)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
@ -38,33 +38,33 @@ t_list *ft_ra_rb(t_list **list, s_list **process, char type)
|
||||
*list = (*list)->next;
|
||||
swap->next = 0;
|
||||
if (type == 'a')
|
||||
s_lstadd_back(process, new_slist("ra\n"));
|
||||
s_lstadd_back(process, new_slist("ra"));
|
||||
else if (type == 'b')
|
||||
s_lstadd_back(process, new_slist("rb\n"));
|
||||
s_lstadd_back(process, new_slist("rb"));
|
||||
}
|
||||
|
||||
t_list *ft_pa(t_list **list_a, t_list **list_b, s_list **process)
|
||||
t_list *ft_pa(t_list **list_a, t_list **list_b, t_slist **process)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
swap = *list_b;
|
||||
*list_b = (*list_b)->next;
|
||||
ft_lstadd_front(list_a, swap);
|
||||
s_lstadd_back(process, new_slist("pa\n"));
|
||||
s_lstadd_back(process, new_slist("pa"));
|
||||
return (*list_b);
|
||||
}
|
||||
|
||||
t_list *ft_pb(t_list **list_a, t_list **list_b, s_list **process)
|
||||
void ft_pb(t_list **list_a, t_list **list_b, t_slist **process)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
swap = *list_a;
|
||||
*list_a = (*list_a)->next;
|
||||
ft_lstadd_front(list_b, swap);
|
||||
s_lstadd_back(process, new_slist("pb\n"));
|
||||
s_lstadd_back(process, new_slist("pb"));
|
||||
}
|
||||
|
||||
t_list * ft_rra_rrb(t_list **list, s_list **process, char type)
|
||||
void ft_rra_rrb(t_list **list, t_slist **process, char type)
|
||||
{
|
||||
t_list *swap;
|
||||
|
||||
@ -72,7 +72,7 @@ t_list * ft_rra_rrb(t_list **list, s_list **process, char type)
|
||||
ft_lstbeforelast(*list)->next = 0;
|
||||
ft_lstadd_front(list, swap);
|
||||
if (type == 'a')
|
||||
s_lstadd_back(process, new_slist("rra\n"));
|
||||
s_lstadd_back(process, new_slist("rra"));
|
||||
else if (type == 'b')
|
||||
s_lstadd_back(process, new_slist("rrb\n"));
|
||||
s_lstadd_back(process, new_slist("rrb"));
|
||||
}
|
||||
|
||||
62
push_swap.c
62
push_swap.c
@ -6,27 +6,12 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:10:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/15 23:28:47 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 15:44:11 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;
|
||||
}
|
||||
printf("----end_print----\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int is_nbr(int nbrarg, char **list)
|
||||
{
|
||||
int i;
|
||||
@ -96,35 +81,11 @@ int push_swap(int nbrarg, char **list)
|
||||
if (ft_lstsize(start) == 1)
|
||||
return (1);
|
||||
lst_indexing(start);
|
||||
find_loop_index(start);
|
||||
start = find_loop_index(start);
|
||||
ft_lstclear(&start, &free);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*t_list *set_list(int nbrarg, char **srcs)
|
||||
{
|
||||
int *tmp;
|
||||
t_list *start;
|
||||
t_list *swap;
|
||||
|
||||
start = 0;
|
||||
swap = 0;
|
||||
*(srcs)++;
|
||||
tmp = ft_calloc(sizeof(int), 1);
|
||||
*tmp = ft_atoi*(srcs);
|
||||
start = ft_lstnew(tmp);
|
||||
swap = start;
|
||||
while (--nbrarg)
|
||||
{
|
||||
*(srcs)++;
|
||||
tmp = ft_calloc(sizeof(int), 1);
|
||||
*tmp = ft_atoi*(srcs);
|
||||
swap->next = ft_lstnew(tmp);
|
||||
swap = swap->next;
|
||||
}
|
||||
return (start);
|
||||
}*/
|
||||
|
||||
t_list *set_list(int nbrarg, char **srcs)
|
||||
{
|
||||
int *tmp;
|
||||
@ -153,3 +114,22 @@ t_list *set_list(int nbrarg, char **srcs)
|
||||
}
|
||||
return (swap);
|
||||
}
|
||||
|
||||
t_list *best_b(t_list **b, t_list *start_b, t_list *a, int best_move)
|
||||
{
|
||||
int move;
|
||||
t_list *best_b;
|
||||
|
||||
move = 0;
|
||||
while (*b)
|
||||
{
|
||||
move = find_nbr(ft_lstsize(start_b), a, start_b, (*b)->index);
|
||||
if (move < best_move)
|
||||
{
|
||||
best_move = move;
|
||||
best_b = *b;
|
||||
}
|
||||
*b = (*b)->next;
|
||||
}
|
||||
return (best_b);
|
||||
}
|
||||
|
||||
61
push_swap.h
61
push_swap.h
@ -6,22 +6,22 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/11/25 23:15:17 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/14 23:03:47 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 15:46:29 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
#ifndef PUSH_SWAP_H
|
||||
# define PUSH_SWAP_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
# include "./libft/libft.h"
|
||||
|
||||
typedef struct process_list
|
||||
typedef struct procest_slist
|
||||
{
|
||||
void *action;
|
||||
struct process_list *next;
|
||||
} s_list;
|
||||
struct procest_slist *next;
|
||||
} t_slist;
|
||||
|
||||
void sort3(t_list *list);
|
||||
int push_swap(int nbrarg, char **list);
|
||||
@ -30,32 +30,43 @@ 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);
|
||||
void find_loop_index(t_list *list);
|
||||
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);
|
||||
|
||||
/*t_slist fonction*/
|
||||
t_slist *new_slist(void *content);
|
||||
void s_lstadd_back(t_slist **alst, t_slist *new);
|
||||
t_slist *s_lstlast(t_slist *lst);
|
||||
void s_lstclear(t_slist **lst);
|
||||
void printf_slist(t_slist *start);
|
||||
|
||||
s_list *new_slist(void *content);
|
||||
void s_lstadd_back(s_list **alst, s_list *new);
|
||||
s_list *s_lstlast(s_list *lst);
|
||||
void s_lstclear(s_list **lst);
|
||||
void printf_slist(s_list *start);
|
||||
/*process fonction*/
|
||||
void ft_sa_sb(t_list **list, t_slist **process, char type, int set);
|
||||
void ft_ra_rb(t_list **list, t_slist **process, char type);
|
||||
t_list *ft_pa(t_list **list_a, t_list **list_b, t_slist **process);
|
||||
void ft_pb(t_list **list_a, t_list **list_b, t_slist **process);
|
||||
void ft_rra_rrb(t_list **list, t_slist **process, char type);
|
||||
|
||||
t_list *ft_sa_sb(t_list **list, s_list **process, char type, int set);
|
||||
t_list *ft_ra_rb(t_list **list, s_list **process, char type);
|
||||
t_list *ft_pa(t_list **list_a, t_list **list_b, s_list **process);
|
||||
t_list *ft_pb(t_list **list_a, t_list **list_b, s_list **process);
|
||||
t_list *ft_rra_rrb(t_list **list, s_list **process, char type);
|
||||
|
||||
t_list *swap(t_list *a, t_list **b, s_list **action, t_list *to_swap);
|
||||
t_list *make_list(int place, t_list *list, s_list *action, char type);
|
||||
t_list *swap_to_a(t_list *a, t_list *b, t_list *start_b, s_list *action);
|
||||
/*sort fonction*/
|
||||
t_list *best_b(t_list **b, t_list *start_b, t_list *a, int best_move);
|
||||
t_list *swap(t_list *a, t_list **b, t_slist **action, t_list *to_swap);
|
||||
t_list *make_list(int place, t_list *list, t_slist *action, char type);
|
||||
t_list *swap_to_a(t_list *a, t_list *b, t_list *start_b, t_slist *action);
|
||||
t_list *is_swap(t_list *list, t_slist **action, int *loop, t_list *best);
|
||||
int find_place_for_b(t_list *list, int index, int size_b);
|
||||
int find_nbr(int size_b, t_list *a, t_list *b, int index_b);
|
||||
void swap_to_b(t_list *list, t_list *best, t_list *b, int loop);
|
||||
t_list *turn_list(t_list *a, s_list *action);
|
||||
|
||||
void printf_list(t_list *start);
|
||||
t_list *swap_to_b(t_list *list, t_list *best, t_list *b, int loop);
|
||||
t_list *turn_list(t_list *a, t_slist *action);
|
||||
|
||||
/*optimise list of action*/
|
||||
t_slist *transform_list(t_slist *start, t_slist *start2, int r1, int r2);
|
||||
t_slist *transform_list2(t_slist *start, t_slist *start2, int r1, int r2);
|
||||
t_slist *sequence(t_slist *lst, t_slist *start1, t_slist *start2, int r1);
|
||||
t_slist *sequence2(t_slist *lst, t_slist *start1, t_slist *start2, int r1);
|
||||
void optimise_move(t_slist **action, t_slist *next_start, int r1);
|
||||
void optimise_move2(t_slist **action, t_slist *start2, int r1);
|
||||
void cut_lst(t_slist *lst);
|
||||
int ft_strcmp(const char *s1, t_slist *str);
|
||||
|
||||
#endif
|
||||
51
set_a.c
51
set_a.c
@ -6,13 +6,13 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/07 19:14:03 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/15 23:30:15 by apommier ### ########.fr */
|
||||
/* Updated: 2022/01/17 15:07:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void find_loop_index(t_list *list)
|
||||
t_list *find_loop_index(t_list *list)
|
||||
{
|
||||
t_list *start;
|
||||
t_list *save;
|
||||
@ -33,8 +33,8 @@ void find_loop_index(t_list *list)
|
||||
list = list->next;
|
||||
}
|
||||
find_loop(start, save, 1);
|
||||
swap_to_b(start, save, 0, loop_size2);
|
||||
|
||||
list = swap_to_b(start, save, 0, loop_size2);
|
||||
return (list);
|
||||
}
|
||||
|
||||
int find_loop(t_list *start, t_list *list, int setswap)
|
||||
@ -66,26 +66,16 @@ int find_loop(t_list *start, t_list *list, int setswap)
|
||||
return (loop_size);
|
||||
}
|
||||
|
||||
void swap_to_b(t_list *list, t_list *best, t_list *b, int loop)
|
||||
t_list *swap_to_b(t_list *list, t_list *best, t_list *b, int loop)
|
||||
{
|
||||
int swap;
|
||||
int lst_size;
|
||||
s_list *action;
|
||||
t_slist *action;
|
||||
|
||||
action = 0;
|
||||
lst_size = ft_lstsize(list);
|
||||
swap = 0;
|
||||
while (lst_size)
|
||||
{
|
||||
ft_sa_sb(&list, &action, 'a', 0);
|
||||
swap = find_loop(list, best, 0);
|
||||
if (swap > loop)
|
||||
{
|
||||
loop = swap;
|
||||
s_lstadd_back(&action, new_slist("sa\n"));
|
||||
}
|
||||
else
|
||||
ft_sa_sb(&list, &action, 'a', 0);
|
||||
list = is_swap(list, &action, &loop, best);
|
||||
if (list->swap)
|
||||
ft_pb(&list, &b, &action);
|
||||
else
|
||||
@ -94,11 +84,14 @@ void swap_to_b(t_list *list, t_list *best, t_list *b, int loop)
|
||||
}
|
||||
list = swap_to_a(list, b, b, action);
|
||||
list = turn_list(list, action);
|
||||
optimise_move(&action, 0, 0);
|
||||
optimise_move2(&action, 0, 0);
|
||||
printf_slist(action);
|
||||
s_lstclear(&action);
|
||||
return (list);
|
||||
}
|
||||
|
||||
t_list *turn_list(t_list *a, s_list *action)
|
||||
t_list *turn_list(t_list *a, t_slist *action)
|
||||
{
|
||||
t_list *start;
|
||||
int place;
|
||||
@ -111,19 +104,33 @@ t_list *turn_list(t_list *a, s_list *action)
|
||||
place++;
|
||||
}
|
||||
a = start;
|
||||
//printf("place = %d size = %d\n", place, ft_lstsize(a));
|
||||
if (place > ft_lstsize(a) / 2 && place > 2)
|
||||
{
|
||||
//printf("if\n");
|
||||
while (ft_lstsize(start) - (place++))
|
||||
ft_rra_rrb(&start, &action, 'a');
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("else\n");
|
||||
while (place--)
|
||||
ft_ra_rb(&start, &action, 'a');
|
||||
}
|
||||
//printf_list(start);
|
||||
return (start);
|
||||
}
|
||||
|
||||
t_list *is_swap(t_list *list, t_slist **action, int *loop, t_list *best)
|
||||
{
|
||||
int swap;
|
||||
|
||||
swap = 0;
|
||||
ft_sa_sb(&list, action, 'a', 0);
|
||||
swap = find_loop(list, best, 0);
|
||||
if (swap > *loop + 1)
|
||||
{
|
||||
*loop = swap;
|
||||
s_lstadd_back(action, new_slist("sa"));
|
||||
find_loop(list, best, 1);
|
||||
}
|
||||
else
|
||||
ft_sa_sb(&list, action, 'a', 0);
|
||||
return (list);
|
||||
}
|
||||
|
||||
0
sort_liltte.c
Normal file
0
sort_liltte.c
Normal file
64
sorting.c
64
sorting.c
@ -12,27 +12,27 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *swap(t_list *a, t_list **b, s_list **action, t_list *to_swap)
|
||||
t_list *swap(t_list *a, t_list **b, t_slist **action, t_list *to_swap)
|
||||
{
|
||||
int rotate;
|
||||
int place_for_b;
|
||||
int place;
|
||||
t_list *start_b;
|
||||
|
||||
start_b = *b;
|
||||
place = 0;
|
||||
rotate = 0;
|
||||
while ((*b)->index != to_swap->index)
|
||||
{
|
||||
place++;
|
||||
*b = (*b)->next;
|
||||
}
|
||||
start_b = make_list(place, start_b, *action, 'b');
|
||||
a = make_list(find_place_for_b(a, to_swap->index, ft_lstsize(start_b)), a, *action, 'a');
|
||||
place_for_b = find_place_for_b(a, to_swap->index, ft_lstsize(start_b));
|
||||
a = make_list(place_for_b, a, *action, 'a');
|
||||
*b = ft_pa(&a, &start_b, action);
|
||||
return (a);
|
||||
}
|
||||
|
||||
t_list *make_list(int place, t_list *list, s_list *action, char type)
|
||||
t_list *make_list(int place, t_list *list, t_slist *action, char type)
|
||||
{
|
||||
int lstsize;
|
||||
|
||||
@ -49,7 +49,6 @@ t_list *make_list(int place, t_list *list, s_list *action, char type)
|
||||
{
|
||||
while (place)
|
||||
{
|
||||
|
||||
ft_ra_rb(&list, &action, type);
|
||||
place--;
|
||||
}
|
||||
@ -57,16 +56,15 @@ t_list *make_list(int place, t_list *list, s_list *action, char type)
|
||||
return (list);
|
||||
}
|
||||
|
||||
t_list *swap_to_a(t_list *a, t_list *b, t_list *start_b, s_list *action)
|
||||
t_list *swap_to_a(t_list *a, t_list *b, t_list *start_b, t_slist *action)
|
||||
{
|
||||
int lst_size;
|
||||
int size_b;
|
||||
int move;
|
||||
int best_move;
|
||||
t_list *best_b;
|
||||
int i = 0;
|
||||
t_list *to_swap;
|
||||
|
||||
best_b = 0;
|
||||
to_swap = 0;
|
||||
size_b = ft_lstsize(b);
|
||||
move = size_b + ft_lstsize(a);
|
||||
best_move = move;
|
||||
@ -75,17 +73,8 @@ t_list *swap_to_a(t_list *a, t_list *b, t_list *start_b, s_list *action)
|
||||
{
|
||||
best_move = ft_lstsize(a) + ft_lstsize(b);
|
||||
b = start_b;
|
||||
while (b)
|
||||
{
|
||||
move = find_nbr(ft_lstsize(start_b), a, start_b, b->index);
|
||||
if (move < best_move)
|
||||
{
|
||||
best_move = move;
|
||||
best_b = b;
|
||||
}
|
||||
b = b->next;
|
||||
}
|
||||
a = swap(a, &start_b, &action, best_b);
|
||||
to_swap = best_b(&b, start_b, a, best_move);
|
||||
a = swap(a, &start_b, &action, to_swap);
|
||||
lst_size--;
|
||||
}
|
||||
return (a);
|
||||
@ -137,36 +126,3 @@ int find_nbr(int size_b, t_list *a, t_list *b, int index_b)
|
||||
move += place;
|
||||
return (move);
|
||||
}
|
||||
|
||||
/*void choose_swap(t_list *a, t_list *b, s_list *action, int lst_size)
|
||||
{
|
||||
int size_a;
|
||||
int size_b;
|
||||
t_list *save_b;
|
||||
int move;
|
||||
int save_move;
|
||||
|
||||
size_b = lst_size;
|
||||
size_a = ft_lstsize(a);
|
||||
printf("swapto a\n");
|
||||
move = 0;
|
||||
save_move = size_b + size_a;
|
||||
while (lst_size)
|
||||
{
|
||||
move = find_place_for_b(a, b->index);
|
||||
if (move > size_a / 2)
|
||||
move = size_a - move;
|
||||
if (lst_size < size_b / 2)
|
||||
move += size_b - lst_size;
|
||||
else
|
||||
move += lst_size;
|
||||
if (move < save_move)
|
||||
{
|
||||
save_move = move;
|
||||
save_b = b;
|
||||
}
|
||||
b = b->next;
|
||||
lst_size--;
|
||||
}
|
||||
find_nbr();
|
||||
}*/
|
||||
@ -1,7 +1,7 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* s_list.c :+: :+: :+: */
|
||||
/* t_slist.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
@ -12,11 +12,11 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
s_list *new_slist(void *content)
|
||||
t_slist *new_slist(void *content)
|
||||
{
|
||||
s_list *new;
|
||||
t_slist *new;
|
||||
|
||||
new = (s_list*)malloc(sizeof(s_list));
|
||||
new = (t_slist *)malloc(sizeof(t_slist));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->action = content;
|
||||
@ -24,9 +24,9 @@ s_list *new_slist(void *content)
|
||||
return (new);
|
||||
}
|
||||
|
||||
void s_lstclear(s_list **lst)
|
||||
void s_lstclear(t_slist **lst)
|
||||
{
|
||||
s_list *chr;
|
||||
t_slist *chr;
|
||||
|
||||
chr = *lst;
|
||||
while (*lst)
|
||||
@ -38,7 +38,7 @@ void s_lstclear(s_list **lst)
|
||||
lst = 0;
|
||||
}
|
||||
|
||||
void s_lstadd_back(s_list **alst, s_list *new)
|
||||
void s_lstadd_back(t_slist **alst, t_slist *new)
|
||||
{
|
||||
if (*alst == 0)
|
||||
*alst = new;
|
||||
@ -47,26 +47,24 @@ void s_lstadd_back(s_list **alst, s_list *new)
|
||||
new->next = 0;
|
||||
}
|
||||
|
||||
s_list *s_lstlast(s_list *lst)
|
||||
t_slist *s_lstlast(t_slist *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
{
|
||||
//printf("test lst = %s\n", (char*)lst->action);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
|
||||
void printf_slist(s_list *start)
|
||||
void printf_slist(t_slist *start)
|
||||
{
|
||||
int i = 0;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (start)
|
||||
{
|
||||
i++;
|
||||
ft_putstr_fd((char*)start->action, 1);
|
||||
ft_putendl_fd((char *)start->action, 1);
|
||||
start = start->next;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user