Compare commits
18 Commits
3fc361618c
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
5a11c5f4cb | ||
|
d6d98b954f | ||
|
eb861b6b98 | ||
|
1b2796bdaf | ||
|
3c4dbf912b | ||
|
337fb1ad2f | ||
|
8aa1e733ac | ||
|
0b3ba46116 | ||
|
e0f584fd30 | ||
|
558f8edfab | ||
|
e7d88896e7 | ||
|
079902b834 | ||
|
3d54238d24 | ||
|
735c6af817 | ||
|
b993e0e68a | ||
|
d7cd178119 | ||
|
9ab20ed483 | ||
|
efab9452b1 |
45
Makefile
45
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2019/02/23 14:30:57 by tmaze #+# #+# #
|
# Created: 2019/02/23 14:30:57 by tmaze #+# #+# #
|
||||||
# Updated: 2019/03/06 11:37:28 by tmaze ### ########.fr #
|
# Updated: 2019/03/18 14:27:44 by tmaze ### ########.fr #
|
||||||
# #
|
# #
|
||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ endif
|
|||||||
|
|
||||||
# Compilator
|
# Compilator
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FLAGS = -Wall -Wextra -g
|
FLAGS = -Wall -Wextra -Werror
|
||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
LIBDIR = libft
|
LIBDIR = libft
|
||||||
@@ -37,12 +37,16 @@ OBJDIR = objs
|
|||||||
INCDIR = includes libft
|
INCDIR = includes libft
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
SRC = ps_push.c \
|
SRC = ps_clean.c \
|
||||||
|
ps_push.c \
|
||||||
ps_rot.c \
|
ps_rot.c \
|
||||||
ps_rerot.c \
|
ps_rerot.c \
|
||||||
ps_swap.c \
|
ps_swap.c \
|
||||||
ps_stktools.c \
|
ps_stktools.c \
|
||||||
ps_stktools2.c
|
ps_stktools2.c \
|
||||||
|
ps_sort.c \
|
||||||
|
ps_sorttools.c \
|
||||||
|
ps_specsort.c
|
||||||
|
|
||||||
MAIN1 = checker.c
|
MAIN1 = checker.c
|
||||||
MAIN2 = push_swap.c
|
MAIN2 = push_swap.c
|
||||||
@@ -60,53 +64,52 @@ OBJP = $(addprefix $(OBJDIR)/, $(SRC:.c=.o))
|
|||||||
OBJP1 = $(addprefix $(OBJDIR)/, $(MAIN1:.c=.o))
|
OBJP1 = $(addprefix $(OBJDIR)/, $(MAIN1:.c=.o))
|
||||||
OBJP2 = $(addprefix $(OBJDIR)/, $(MAIN2:.c=.o))
|
OBJP2 = $(addprefix $(OBJDIR)/, $(MAIN2:.c=.o))
|
||||||
INCP = $(foreach dir, $(INCDIR), -I$(dir))
|
INCP = $(foreach dir, $(INCDIR), -I$(dir))
|
||||||
OBJS_DIRS = $(sort $(dir $(OBJP)))
|
|
||||||
# Default Rule
|
# Default Rule
|
||||||
DRULE = all
|
DRULE = all
|
||||||
|
|
||||||
# Main rules
|
# Main rules
|
||||||
default :
|
default :
|
||||||
@echo -e "$(PUR)===> $(GRE)$(NAME) : $(PUR) START RULE : $(DRULE) <===$(DEF)"
|
@echo -e "$(PUR)===> $(GRE)$(NAME2) : $(PUR) START RULE : $(DRULE) <===$(DEF)"
|
||||||
@make $(DRULE)
|
@make $(DRULE)
|
||||||
@echo -e "$(PUR)===> $(GRE)$(NAME) : $(PUR) END RULE : $(DRULE) <===$(DEF)"
|
@echo -e "$(PUR)===> $(GRE)$(NAME2) : $(PUR) END RULE : $(DRULE) <===$(DEF)"
|
||||||
|
|
||||||
all : $(NAME1) $(NAME2)
|
all : $(NAME1) $(NAME2)
|
||||||
|
|
||||||
re : fclean default
|
|
||||||
|
|
||||||
# Compilation rules
|
# Compilation rules
|
||||||
|
|
||||||
$(OBJDIR)/%.o : $(SRCDIR)/%.c $(OBJDIR)
|
$(OBJDIR)/%.o : $(SRCDIR)/%.c includes/push_swap.h
|
||||||
|
@mkdir -p $(OBJDIR)
|
||||||
$(CC) $(FLAGS) -c -o $@ $< $(INCP)
|
$(CC) $(FLAGS) -c -o $@ $< $(INCP)
|
||||||
|
|
||||||
$(OBJDIR) :
|
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Objects Compilation <===$(DEF)"
|
|
||||||
@mkdir -p $(OBJDIR)
|
|
||||||
@mkdir -p $(OBJS_DIRS)
|
|
||||||
|
|
||||||
$(LIBDIR)/$(LIBFILE) :
|
$(LIBDIR)/$(LIBFILE) :
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Librairy Compilation <===$(DEF)"
|
@echo -e "$(YEL)===> $(GRE)$(NAME2) : $(YEL) Librairy Compilation <===$(DEF)"
|
||||||
$(MAKE) -C $(LIBDIR) all
|
$(MAKE) -C $(LIBDIR) all
|
||||||
|
|
||||||
$(NAME1) : $(OBJP1) $(OBJP) $(LIBDIR)/$(LIBFILE)
|
$(NAME1) : $(OBJP1) $(OBJP) $(LIBDIR)/$(LIBFILE)
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Binary Compilation <===$(DEF)"
|
@echo -e "$(YEL)===> $(GRE)$(NAME1) : $(YEL) Binary Compilation <===$(DEF)"
|
||||||
$(CC) $(FLAGS) -o $@ $^ $(INCP) -L$(LIBDIR) -l$(LIB)
|
$(CC) $(FLAGS) -o $@ $^ $(INCP) -L$(LIBDIR) -l$(LIB)
|
||||||
|
|
||||||
$(NAME2) : $(OBJP2) $(OBJP) $(LIBDIR)/$(LIBFILE)
|
$(NAME2) : $(OBJP2) $(OBJP) $(LIBDIR)/$(LIBFILE)
|
||||||
@echo -e "$(YEL)===> $(GRE)$(NAME) : $(YEL) Binary Compilation <===$(DEF)"
|
@echo -e "$(YEL)===> $(GRE)$(NAME2) : $(YEL) Binary Compilation <===$(DEF)"
|
||||||
$(CC) $(FLAGS) -o $@ $^ $(INCP) -L$(LIBDIR) -l$(LIB)
|
$(CC) $(FLAGS) -o $@ $^ $(INCP) -L$(LIBDIR) -l$(LIB)
|
||||||
|
|
||||||
# Cleaner rules
|
# Cleaner rules
|
||||||
clean :
|
clean :
|
||||||
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Object Files <===$(DEF)"
|
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Object Files <===$(DEF)"
|
||||||
@rm -rf $(OBJDIR)
|
@$(RM) -rf $(OBJDIR)
|
||||||
|
@$(MAKE) -C $(LIBDIR) clean
|
||||||
|
|
||||||
fclean : clean
|
fclean : clean
|
||||||
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Binary File <===$(DEF)"
|
@echo -e "$(RED)===> $(GRE)$(NAME) : $(RED) Delete Binary File <===$(DEF)"
|
||||||
@rm -f $(NAME1) $(NAME2)
|
@$(RM) -f $(NAME1) $(NAME2)
|
||||||
|
@$(RM) -rf *.dSYM
|
||||||
|
@$(MAKE) -C $(LIBDIR) fclean
|
||||||
|
|
||||||
|
re : fclean default
|
||||||
|
|
||||||
# Phony
|
# Phony
|
||||||
.PHONY = default all re clean fclean $(OBJDIR) $(NAME)
|
.PHONY = default all re clean fclean
|
||||||
# Color
|
# Color
|
||||||
DEF = \033[0m
|
DEF = \033[0m
|
||||||
BLA = \033[30m
|
BLA = \033[30m
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/06 11:07:38 by tmaze ### ########.fr */
|
/* Updated: 2019/03/20 12:24:09 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,8 +17,6 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
|
||||||
# include <stdio.h>
|
|
||||||
|
|
||||||
typedef struct s_stack
|
typedef struct s_stack
|
||||||
{
|
{
|
||||||
int nb;
|
int nb;
|
||||||
@@ -33,11 +31,9 @@ typedef struct s_psdata
|
|||||||
size_t size_a;
|
size_t size_a;
|
||||||
size_t size_b;
|
size_t size_b;
|
||||||
t_list *op;
|
t_list *op;
|
||||||
|
char viz;
|
||||||
} t_psdata;
|
} t_psdata;
|
||||||
|
|
||||||
char **ft_strsplitwhitespace(char *s);
|
|
||||||
int ft_iswhitespace(char c);
|
|
||||||
|
|
||||||
t_stack *ps_stknew(int nb);
|
t_stack *ps_stknew(int nb);
|
||||||
void ps_stkpsh(t_psdata *data, char c, t_stack *new);
|
void ps_stkpsh(t_psdata *data, char c, t_stack *new);
|
||||||
t_stack *ps_stkpop(t_psdata *data, char c);
|
t_stack *ps_stkpop(t_psdata *data, char c);
|
||||||
@@ -53,7 +49,21 @@ void ps_rerot(t_psdata *data, char c);
|
|||||||
void ps_rrerot(t_psdata *data);
|
void ps_rrerot(t_psdata *data);
|
||||||
|
|
||||||
int is_op(char *buff);
|
int is_op(char *buff);
|
||||||
int get_params(t_psdata *data, int ac, char **av);
|
t_list *add_op(t_psdata *data, char *op);
|
||||||
int check_input(char *in, int *ret);
|
int get_params(t_psdata *data, int ac, char **av, int viz);
|
||||||
|
int check_input(t_psdata *data, char *in, int *ret);
|
||||||
|
|
||||||
|
void mark_groups(t_psdata *data);
|
||||||
|
t_stack *get_last_a(t_psdata *data);
|
||||||
|
int get_size_firsts(t_psdata *data);
|
||||||
|
int get_size_last(t_psdata *data);
|
||||||
|
int get_nb_groups(t_psdata *data);
|
||||||
|
|
||||||
|
void sortfor3(t_psdata *data);
|
||||||
|
void sortfor5(t_psdata *data);
|
||||||
|
|
||||||
|
void clean_op(t_psdata *data);
|
||||||
|
|
||||||
|
int sort(t_psdata *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
2
libft
2
libft
Submodule libft updated: e6970465e9...f798c9ce1d
@@ -6,12 +6,38 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/02 18:28:08 by tmaze ### ########.fr */
|
/* Updated: 2019/03/20 12:26:46 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
#define VISU_SPEED 500000
|
||||||
|
|
||||||
|
void debug(t_psdata *data, char *com)
|
||||||
|
{
|
||||||
|
t_stack *as;
|
||||||
|
t_stack *bs;
|
||||||
|
|
||||||
|
as = data->a;
|
||||||
|
bs = data->b;
|
||||||
|
ft_printf(FT_CLEAR);
|
||||||
|
ft_printf("============== %4s ==============\n", com);
|
||||||
|
while (as || bs)
|
||||||
|
{
|
||||||
|
if (as && bs)
|
||||||
|
ft_printf("%5d || %5d\n", as->nb, bs->nb);
|
||||||
|
else if (!as && bs)
|
||||||
|
ft_printf("%5c || %5d\n", ' ', bs->nb);
|
||||||
|
else if (as && !bs)
|
||||||
|
ft_printf("%5d || %5c\n", as->nb, ' ');
|
||||||
|
as = (as) ? as->next : as;
|
||||||
|
bs = (bs) ? bs->next : bs;
|
||||||
|
}
|
||||||
|
ft_printf("==================================\n");
|
||||||
|
usleep(VISU_SPEED);
|
||||||
|
}
|
||||||
|
|
||||||
void exec_actions(t_psdata *data)
|
void exec_actions(t_psdata *data)
|
||||||
{
|
{
|
||||||
char *buff;
|
char *buff;
|
||||||
@@ -20,9 +46,11 @@ void exec_actions(t_psdata *data)
|
|||||||
nop = data->op;
|
nop = data->op;
|
||||||
while (nop && (buff = (char*)nop->content))
|
while (nop && (buff = (char*)nop->content))
|
||||||
{
|
{
|
||||||
if (ft_strlen(buff) == 2)
|
if (ft_strcmp(buff, "rra") == 0 || ft_strcmp(buff, "rrb") == 0)
|
||||||
{
|
ps_rerot(data, buff[2]);
|
||||||
if (buff[0] == 's' && buff[1] != 's')
|
else if (ft_strcmp(buff, "rrr") == 0)
|
||||||
|
ps_rrerot(data);
|
||||||
|
else if (buff[0] == 's' && buff[1] != 's')
|
||||||
ps_swap(data, buff[1]);
|
ps_swap(data, buff[1]);
|
||||||
else if (buff[0] == 's' && buff[1] == 's')
|
else if (buff[0] == 's' && buff[1] == 's')
|
||||||
ps_sswap(data);
|
ps_sswap(data);
|
||||||
@@ -32,11 +60,8 @@ void exec_actions(t_psdata *data)
|
|||||||
ps_rrot(data);
|
ps_rrot(data);
|
||||||
else if (buff[0] == 'p')
|
else if (buff[0] == 'p')
|
||||||
ps_push(data, buff[1]);
|
ps_push(data, buff[1]);
|
||||||
}
|
if (data->viz)
|
||||||
else if (buff[2] != 'r')
|
debug(data, buff);
|
||||||
ps_rerot(data, buff[2]);
|
|
||||||
else if (buff[2] == 'r')
|
|
||||||
ps_rrerot(data);
|
|
||||||
nop = nop->next;
|
nop = nop->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,20 +69,26 @@ void exec_actions(t_psdata *data)
|
|||||||
int read_ops(t_psdata *data)
|
int read_ops(t_psdata *data)
|
||||||
{
|
{
|
||||||
t_list *nop;
|
t_list *nop;
|
||||||
char buff[5];
|
char *buff;
|
||||||
|
char tmp[4];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ft_memset(buff, '\0', 5);
|
buff = NULL;
|
||||||
while ((ret = read(1, buff, 4)) > 0)
|
ft_bzero(tmp, 4);
|
||||||
|
while ((ret = ft_getline(&buff)) > 0)
|
||||||
{
|
{
|
||||||
buff[ft_strlen(buff) - 1] = '\0';
|
ft_strncpy(tmp, buff, 3);
|
||||||
if (ret > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
|
if (ft_strlen(buff) > 4 || !is_op(buff)
|
||||||
|
|| (nop = ft_lstnew(tmp, 4)) == NULL)
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error", 2);
|
ft_putendl_fd("Error", 2);
|
||||||
|
ft_strdel(&buff);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_lstaddend(&(data->op), nop);
|
ft_lstaddend(&(data->op), nop);
|
||||||
|
ft_strdel(&buff);
|
||||||
}
|
}
|
||||||
|
ft_strdel(&buff);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +98,11 @@ void check_stack(t_psdata *data)
|
|||||||
int nb;
|
int nb;
|
||||||
|
|
||||||
ind = data->a;
|
ind = data->a;
|
||||||
|
if (ind)
|
||||||
nb = ind->nb;
|
nb = ind->nb;
|
||||||
while (ind)
|
while (ind)
|
||||||
{
|
{
|
||||||
if (ind->nb < nb)
|
if (ind->nb < nb || data->size_b > 0)
|
||||||
{
|
{
|
||||||
ft_putendl("KO");
|
ft_putendl("KO");
|
||||||
return ;
|
return ;
|
||||||
@@ -78,8 +110,10 @@ void check_stack(t_psdata *data)
|
|||||||
nb = ind->nb;
|
nb = ind->nb;
|
||||||
ind = ind->next;
|
ind = ind->next;
|
||||||
}
|
}
|
||||||
if (!ind)
|
if (!ind && data->size_b == 0)
|
||||||
ft_putendl("OK");
|
ft_putendl("OK");
|
||||||
|
else
|
||||||
|
ft_putendl("KO");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
@@ -90,11 +124,11 @@ int main(int ac, char **av)
|
|||||||
|
|
||||||
ps_initdata(&data);
|
ps_initdata(&data);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (!get_params(&data, ac, av))
|
if (!get_params(&data, ac, av, 1))
|
||||||
return (0);
|
return (0);
|
||||||
new = data.a;
|
new = data.a;
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
ft_putendl("Empty");
|
ft_putendl_fd("Error", 2);
|
||||||
if (new == NULL || read_ops(&data))
|
if (new == NULL || read_ops(&data))
|
||||||
{
|
{
|
||||||
ps_stkclean(&data);
|
ps_stkclean(&data);
|
||||||
|
61
srcs/ps_clean.c
Normal file
61
srcs/ps_clean.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ps_clean.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/16 13:14:52 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/03/18 15:19:06 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static void clean_push(t_psdata *data, t_list ***prec, t_list **it)
|
||||||
|
{
|
||||||
|
**prec = (*it)->next->next;
|
||||||
|
ft_memdel(&((*it)->next->content));
|
||||||
|
ft_memdel((void**)(&((*it)->next)));
|
||||||
|
ft_memdel(&((*it)->content));
|
||||||
|
ft_memdel((void**)it);
|
||||||
|
*it = data->op;
|
||||||
|
*prec = &(data->op);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clean_swap(t_psdata *data, t_list ***prec, t_list **it)
|
||||||
|
{
|
||||||
|
**prec = (*it)->next;
|
||||||
|
ft_strcpy((char*)((*it)->next->next->content), "sa");
|
||||||
|
ft_memdel(&((*it)->content));
|
||||||
|
ft_memdel((void**)it);
|
||||||
|
*it = data->op;
|
||||||
|
*prec = &(data->op);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clean_op(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_list *it;
|
||||||
|
t_list **prec;
|
||||||
|
|
||||||
|
it = data->op;
|
||||||
|
prec = &(data->op);
|
||||||
|
while (it && it->next)
|
||||||
|
{
|
||||||
|
if (((char*)(it->content))[0] == 'p'
|
||||||
|
&& ((char*)(it->next->content))[0] == 'p'
|
||||||
|
&& ((char*)(it->content))[1] != ((char*)(it->next->content))[1])
|
||||||
|
clean_push(data, &prec, &it);
|
||||||
|
else if (it->next->next && ((char*)(it->content))[0] == 'p'
|
||||||
|
&& ((char*)(it->content))[1] == 'b'
|
||||||
|
&& ((char*)(it->next->next->content))[0] == 'p'
|
||||||
|
&& ((char*)(it->next->next->content))[1] == 'a'
|
||||||
|
&& ft_strcmp((char*)(it->next->content), "rra") == 0)
|
||||||
|
clean_swap(data, &prec, &it);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prec = &(it->next);
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/21 16:32:04 by tmaze #+# #+# */
|
/* Created: 2019/02/21 16:32:04 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/02 17:37:07 by tmaze ### ########.fr */
|
/* Updated: 2019/03/26 15:06:28 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,28 +16,26 @@ void ps_rerot(t_psdata *data, char c)
|
|||||||
{
|
{
|
||||||
t_stack *s;
|
t_stack *s;
|
||||||
t_stack *tmp;
|
t_stack *tmp;
|
||||||
size_t size;
|
size_t *size;
|
||||||
|
|
||||||
if (c == 'a')
|
if (c == 'a')
|
||||||
s = data->a;
|
s = data->a;
|
||||||
if (c == 'a')
|
if (c == 'a')
|
||||||
size = data->size_a;
|
size = &(data->size_a);
|
||||||
else if (c == 'b')
|
else if (c == 'b')
|
||||||
s = data->b;
|
s = data->b;
|
||||||
if (c == 'b')
|
if (c == 'b')
|
||||||
size = data->size_b;
|
size = &(data->size_b);
|
||||||
if (s != NULL && size > 2)
|
if (s != NULL && *size > 2)
|
||||||
{
|
{
|
||||||
tmp = s->next;
|
tmp = s->next;
|
||||||
while (tmp->next != NULL)
|
while (tmp->next != NULL && (tmp = tmp->next))
|
||||||
{
|
|
||||||
tmp = tmp->next;
|
|
||||||
s = s->next;
|
s = s->next;
|
||||||
}
|
|
||||||
s->next = NULL;
|
s->next = NULL;
|
||||||
|
(*size)--;
|
||||||
ps_stkpsh(data, c, tmp);
|
ps_stkpsh(data, c, tmp);
|
||||||
}
|
}
|
||||||
else if (s != NULL && size == 2)
|
else if (s != NULL && *size == 2)
|
||||||
ps_swap(data, c);
|
ps_swap(data, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
89
srcs/ps_sort.c
Normal file
89
srcs/ps_sort.c
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ps_sort.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/16 13:21:02 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/03/19 12:35:27 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static int join_lists(t_psdata *data, t_stack **last, int inds, int inds2)
|
||||||
|
{
|
||||||
|
while ((*last)->ind == inds2 || data->size_b > 0)
|
||||||
|
{
|
||||||
|
if (((*last)->ind != inds2 && data->size_b > 0)
|
||||||
|
|| (data->size_b > 0 && data->b->nb > (*last)->nb))
|
||||||
|
{
|
||||||
|
if (add_op(data, "pa\0") == NULL)
|
||||||
|
return (0);
|
||||||
|
ps_push(data, 'a');
|
||||||
|
data->a->ind = inds;
|
||||||
|
}
|
||||||
|
else if (data->size_b == 0 || data->b->nb < (*last)->nb)
|
||||||
|
{
|
||||||
|
if (add_op(data, "rra") == NULL)
|
||||||
|
return (0);
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
data->a->ind = inds;
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
}
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int rotate_list(t_psdata *data, t_stack **last)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (get_nb_groups(data) > 2)
|
||||||
|
{
|
||||||
|
if (get_nb_groups(data) != 2
|
||||||
|
&& data->a->ind != (*last)->ind && add_op(data, "rra") == NULL)
|
||||||
|
return (0);
|
||||||
|
else if (get_nb_groups(data) != 2 && data->a->ind != (*last)->ind)
|
||||||
|
{
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
while ((*last)->ind == data->a->ind
|
||||||
|
&& (tmp = add_op(data, "rra")) != NULL)
|
||||||
|
{
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
(*last) = get_last_a(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sort(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
t_stack *last;
|
||||||
|
int inds;
|
||||||
|
int inds2;
|
||||||
|
|
||||||
|
last = get_last_a(data);
|
||||||
|
inds = last->ind + 1;
|
||||||
|
while (data->a->ind != last->ind)
|
||||||
|
{
|
||||||
|
inds2 = data->a->ind;
|
||||||
|
while (data->a && data->a->ind == inds2
|
||||||
|
&& (tmp = add_op(data, "pb\0")) != NULL)
|
||||||
|
ps_push(data, 'b');
|
||||||
|
if (tmp == NULL)
|
||||||
|
return (0);
|
||||||
|
inds2 = last->ind;
|
||||||
|
if (join_lists(data, &last, inds, inds2) == 0)
|
||||||
|
return (0);
|
||||||
|
if (rotate_list(data, &last) == 0)
|
||||||
|
return (0);
|
||||||
|
inds++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
100
srcs/ps_sorttools.c
Normal file
100
srcs/ps_sorttools.c
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ps_sorttools.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/16 13:23:27 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/03/16 13:23:57 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
void mark_groups(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
int inds;
|
||||||
|
|
||||||
|
ptr = data->a;
|
||||||
|
inds = 1;
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
ptr->ind = inds;
|
||||||
|
if (ptr->next && ptr->nb > ptr->next->nb)
|
||||||
|
inds++;
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t_stack *get_last_a(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
|
||||||
|
ptr = data->a;
|
||||||
|
while (ptr && ptr->next)
|
||||||
|
ptr = ptr->next;
|
||||||
|
return (ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_size_firsts(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
int inds;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
inds = data->a->ind;
|
||||||
|
i = 0;
|
||||||
|
ptr = data->a;
|
||||||
|
while (ptr && ptr->ind == inds && (i += 1))
|
||||||
|
ptr = ptr->next;
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
inds = ptr->ind;
|
||||||
|
while (ptr && ptr->ind == inds && (i += 1))
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_size_last(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
int inds;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
ptr = data->a;
|
||||||
|
while (ptr && ptr->next)
|
||||||
|
ptr = ptr->next;
|
||||||
|
inds = ptr->ind;
|
||||||
|
ptr = data->a;
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
i += (ptr->ind == inds) ? 1 : 0;
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_nb_groups(t_psdata *data)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
int ind;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
ptr = data->a;
|
||||||
|
ind = ptr->ind;
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
if (ret == 0 || ptr->ind != ind)
|
||||||
|
{
|
||||||
|
ret++;
|
||||||
|
ind = ptr->ind;
|
||||||
|
}
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
}
|
85
srcs/ps_specsort.c
Normal file
85
srcs/ps_specsort.c
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ps_specsort.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/16 13:18:14 by tmaze #+# #+# */
|
||||||
|
/* Updated: 2019/03/16 13:28:12 by tmaze ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
static void get_min_max(t_psdata *data, int *min_max, int *ind_min_max)
|
||||||
|
{
|
||||||
|
t_stack *ptr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
min_max[0] = FT_INT_MAX;
|
||||||
|
min_max[1] = FT_INT_MIN;
|
||||||
|
ptr = data->a;
|
||||||
|
i = 0;
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
if (ptr->nb < min_max[0] && (ind_min_max[0] = i) == i)
|
||||||
|
min_max[0] = ptr->nb;
|
||||||
|
if (ptr->nb > min_max[1] && (ind_min_max[1] = i) == i)
|
||||||
|
min_max[1] = ptr->nb;
|
||||||
|
i++;
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortfor3(t_psdata *data)
|
||||||
|
{
|
||||||
|
int min_max[2];
|
||||||
|
int ind_min_max[2];
|
||||||
|
|
||||||
|
get_min_max(data, min_max, ind_min_max);
|
||||||
|
while (ind_min_max[0] != 0 || ind_min_max[1] != 2)
|
||||||
|
{
|
||||||
|
if (ind_min_max[0] == ind_min_max[1] - 1)
|
||||||
|
ft_printf("sa\n");
|
||||||
|
if (ind_min_max[0] == ind_min_max[1] - 1)
|
||||||
|
ps_swap(data, 'a');
|
||||||
|
if (ind_min_max[1] == 0)
|
||||||
|
ft_printf("ra\n");
|
||||||
|
if (ind_min_max[1] == 0)
|
||||||
|
ps_rot(data, 'a');
|
||||||
|
if (ind_min_max[0] == 2 && ind_min_max[1] == 1)
|
||||||
|
ft_printf("rra\n");
|
||||||
|
if (ind_min_max[0] == 2 && ind_min_max[1] == 1)
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
get_min_max(data, min_max, ind_min_max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortfor5(t_psdata *data)
|
||||||
|
{
|
||||||
|
ft_printf("pb\n");
|
||||||
|
ps_push(data, 'b');
|
||||||
|
ft_printf("pb\n");
|
||||||
|
ps_push(data, 'b');
|
||||||
|
if (data->b->nb > data->b->next->nb)
|
||||||
|
ft_printf("sb\n");
|
||||||
|
if (data->b->nb > data->b->next->nb)
|
||||||
|
ps_swap(data, 'b');
|
||||||
|
sortfor3(data);
|
||||||
|
data->b->ind = 1;
|
||||||
|
data->b->next->ind = 1;
|
||||||
|
data->a->ind = 2;
|
||||||
|
data->a->next->ind = 2;
|
||||||
|
data->a->next->next->ind = 2;
|
||||||
|
while (data->a->ind == 2 || data->size_b > 0)
|
||||||
|
{
|
||||||
|
if (data->a->ind != 2 || (data->b && data->b->nb < data->a->nb))
|
||||||
|
ft_printf("pa\n");
|
||||||
|
if (data->a->ind != 2 || (data->b && data->b->nb < data->a->nb))
|
||||||
|
ps_push(data, 'a');
|
||||||
|
data->a->ind = 3;
|
||||||
|
ft_printf("ra\n");
|
||||||
|
ps_rot(data, 'a');
|
||||||
|
}
|
||||||
|
}
|
@@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/03 13:59:43 by tmaze ### ########.fr */
|
/* Updated: 2019/03/20 16:49:01 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,11 +19,13 @@ void ps_initdata(t_psdata *data)
|
|||||||
data->size_a = 0;
|
data->size_a = 0;
|
||||||
data->size_b = 0;
|
data->size_b = 0;
|
||||||
data->op = NULL;
|
data->op = NULL;
|
||||||
|
data->viz = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_input(char *in, int *ret)
|
int check_input(t_psdata *data, char *in, int *ret)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
t_stack *ptr;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (in[i] && ft_issign(in[i]))
|
if (in[i] && ft_issign(in[i]))
|
||||||
@@ -31,37 +33,45 @@ int check_input(char *in, int *ret)
|
|||||||
while (in[i] && ft_isdigit(in[i]))
|
while (in[i] && ft_isdigit(in[i]))
|
||||||
i++;
|
i++;
|
||||||
if (in[i] == '\0' && ft_hasdigit(in) && ft_atois(in, ret))
|
if (in[i] == '\0' && ft_hasdigit(in) && ft_atois(in, ret))
|
||||||
|
{
|
||||||
|
ptr = data->a;
|
||||||
|
while (ptr)
|
||||||
|
{
|
||||||
|
if (*ret == ptr->nb)
|
||||||
|
return (0);
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_params(t_psdata *data, int ac, char **av)
|
int get_params(t_psdata *data, int ac, char **av, int viz)
|
||||||
{
|
{
|
||||||
t_stack *new;
|
t_stack *new;
|
||||||
char **tab;
|
|
||||||
int nb;
|
int nb;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
|
||||||
|
|
||||||
i = ac;
|
i = ac;
|
||||||
nb = 0;
|
nb = 0;
|
||||||
while (--i > 0 && !(j = 0))
|
while (--i > 0)
|
||||||
if ((tab = ft_strsplitwhitespace(av[i])) != NULL)
|
|
||||||
{
|
{
|
||||||
while (tab[j])
|
if (i == 1 && viz && ft_strcmp(av[i], "-v") == 0)
|
||||||
j++;
|
data->viz = 'a';
|
||||||
while (--j >= 0)
|
else if (check_input(data, av[i], &nb) && (new = ps_stknew(nb)) != NULL)
|
||||||
if (check_input(tab[j], &nb) && (new = ps_stknew(nb)) != NULL)
|
{
|
||||||
|
new->ind = 0;
|
||||||
ps_stkpsh(data, 'a', new);
|
ps_stkpsh(data, 'a', new);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (ft_putendl_fd2("Error", 2))
|
||||||
ft_putendl_fd("Error", 2);
|
ft_putendl_fd("Error", 2);
|
||||||
ps_stkclean(data);
|
ps_stkclean(data);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
ft_del_words_tables(&tab);
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (ac != 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_op(char *buff)
|
int is_op(char *buff)
|
||||||
@@ -75,3 +85,12 @@ int is_op(char *buff)
|
|||||||
i++;
|
i++;
|
||||||
return (i < 11);
|
return (i < 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_list *add_op(t_psdata *data, char *op)
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
|
||||||
|
if ((new = ft_lstnew(op, 4)) != NULL)
|
||||||
|
ft_lstaddend(&(data->op), new);
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
|
115
srcs/push_swap.c
115
srcs/push_swap.c
@@ -6,117 +6,48 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/06 16:24:16 by tmaze ### ########.fr */
|
/* Updated: 2019/03/19 15:24:24 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
int sort(t_psdata *data, int size)
|
void print_ops(t_psdata *data)
|
||||||
{
|
{
|
||||||
t_stack *ptr;
|
t_list *it;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (size > 2)
|
it = data->op;
|
||||||
|
while (it)
|
||||||
{
|
{
|
||||||
if (!sort(data, ((size % 2) ? size + 1 : size) / 2))
|
ft_putendl(it->content);
|
||||||
return (0);
|
it = it->next;
|
||||||
if (!sort(data, size - (((size % 2) ? size + 1 : size) / 2)))
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
else if (size == 1)
|
|
||||||
{
|
|
||||||
printf("ra\n");
|
|
||||||
ps_rot(data, 'a');
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while (size > 2 && i < size)
|
|
||||||
{
|
|
||||||
printf("rra\n");
|
|
||||||
ps_rerot(data, 'a');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
ptr = data->a;
|
|
||||||
while (i < ((size % 2) ? size + 1 : size) / 2)
|
|
||||||
{
|
|
||||||
ptr->ind = 1;
|
|
||||||
ptr = ptr->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while (ptr && i < (size - (((size % 2) ? size + 1 : size) / 2)))
|
|
||||||
{
|
|
||||||
ptr->ind = 2;
|
|
||||||
ptr = ptr->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (data->a->ind == 1)
|
|
||||||
{
|
|
||||||
printf("pb\n");
|
|
||||||
if (!ps_push(data, 'b'))
|
|
||||||
return (0);
|
|
||||||
if (data->size_b > 1)
|
|
||||||
{
|
|
||||||
printf("rb\n");
|
|
||||||
ps_rot(data, 'b');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (data->a->ind != 0 || data->size_b > 0)
|
|
||||||
{
|
|
||||||
if ((data->a->ind != 0 && data->size_b > 0 && data->a->nb > data->b->nb)
|
|
||||||
|| (data->a->ind == 0 && data->size_b > 0))
|
|
||||||
{
|
|
||||||
printf("pa\n");
|
|
||||||
ps_push(data, 'a');
|
|
||||||
}
|
|
||||||
data->a->ind = 0;
|
|
||||||
printf("ra\n");
|
|
||||||
ps_rot(data, 'a');
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_stack *ptr;
|
|
||||||
t_psdata data;
|
t_psdata data;
|
||||||
int i;
|
|
||||||
|
|
||||||
ps_initdata(&data);
|
ps_initdata(&data);
|
||||||
if (!get_params(&data, ac, av))
|
if (!get_params(&data, ac, av, 0))
|
||||||
return (0);
|
return (0);
|
||||||
ptr = data.a;
|
if (data.a == NULL)
|
||||||
if (ptr == NULL)
|
ft_putendl_fd("Error", 2);
|
||||||
ft_putendl("Empty");
|
if (data.size_a == 3)
|
||||||
while (ptr)
|
sortfor3(&data);
|
||||||
|
else if (data.size_a == 5)
|
||||||
|
sortfor5(&data);
|
||||||
|
if (data.size_a != 0 && data.size_a != 3 && data.size_a != 5)
|
||||||
{
|
{
|
||||||
ptr->ind = 0;
|
mark_groups(&data);
|
||||||
ptr = ptr->next;
|
if (sort(&data) == 0)
|
||||||
|
ft_putendl_fd("Error", 2);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clean_op(&data);
|
||||||
|
print_ops(&data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!sort(&data, data.size_a))
|
|
||||||
{
|
|
||||||
printf("Error\n");
|
|
||||||
ps_stkclean(&data);
|
ps_stkclean(&data);
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
/* ptr = data.a; */
|
|
||||||
/* i = data.a->nb; */
|
|
||||||
/* while (ptr) */
|
|
||||||
/* { */
|
|
||||||
/* printf("%d\n", ptr->nb); */
|
|
||||||
/* ptr->ind = 0; */
|
|
||||||
/* if (i != ptr->nb && i > ptr->nb) */
|
|
||||||
/* { */
|
|
||||||
/* printf("KO\n"); */
|
|
||||||
/* break ; */
|
|
||||||
/* } */
|
|
||||||
/* i = ptr->nb; */
|
|
||||||
/* ptr = ptr->next; */
|
|
||||||
/* } */
|
|
||||||
/* if (ptr == NULL) */
|
|
||||||
/* printf("OK\n"); */
|
|
||||||
/* ps_stkclean(&data); */
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user