diff --git a/Makefile b/Makefile index 5b46e72..993f577 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: whaffman +#+ +:+ +#++#++:++#++ # # +#+ +#+#+ +#++#+ +#+ \o/ # # Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | # -# Updated: 2024/11/06 20:10:28 by whaffman ### ### ### ### / \ # +# Updated: 2024/11/07 12:48:24 by whaffman ### ### ### ### / \ # # # # **************************************************************************** # @@ -64,11 +64,12 @@ re: fclean all run: all @$(eval ARG = $(shell shuf -i 0-100 -n 5)) - ./$(NAME) 1 2 3 4 5 6 7 8 9 + ./$(NAME) $(ARG) debug: CFLAGS += -DDEBUG -g -debug: all +debug: fclean @echo $(CFLAGS) - @$(MAKE) re + @$(MAKE) -C libft debug + @$(MAKE) -s .PHONY: all bonus clean fclean re diff --git a/inc/push_swap.h b/inc/push_swap.h index 15c9bf9..f84cf7d 100644 --- a/inc/push_swap.h +++ b/inc/push_swap.h @@ -6,7 +6,7 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/11/04 13:58:35 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/11/06 20:10:14 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/11/07 13:12:32 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ @@ -15,6 +15,12 @@ # include "libft.h" +typedef struct s_state +{ + t_list *a; + t_list *b; +} t_state; + int new_element(t_list **stack, const char *str); t_list *ft_lstat(t_list *list, int n); void print_stack(const char *name, t_list *stack); diff --git a/src/push_swap.c b/src/push_swap.c index 972c9cc..c274435 100644 --- a/src/push_swap.c +++ b/src/push_swap.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/11/04 13:04:11 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/11/06 20:11:40 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/11/07 13:33:13 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ @@ -38,8 +38,10 @@ void print_stack(const char *name, t_list *stack) void print_stacks(t_list *stack_a, t_list *stack_b) { + ft_printf("\n"); print_stack("A", stack_a); print_stack("B", stack_b); + ft_printf("===================\n"); } int main(int argc, char *argv[]) diff --git a/src/sort/sort3.c b/src/sort/sort3.c new file mode 100644 index 0000000..82e893c --- /dev/null +++ b/src/sort/sort3.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: o_ :::::: ::: */ +/* sort3.c :+: / :+::+: :+: */ +/* +:+ > +:++:+ +:+ */ +/* By: whaffman +#+ +:+ +#++#++:++#++ */ +/* +#+ +#+#+ +#++#+ +#+ \o/ */ +/* Created: 2024/11/07 12:09:48 by whaffman #+#+# #+#+# #+# #+# | */ +/* Updated: 2024/11/07 13:33:18 by whaffman ### ### ### ### / \ */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "push_swap.h" + +// abc +// acb rra sa +// bca rra +// bac sa +// cab ra +// cba sa rra + +int sort3(t_list **stack) +{ + const int a = *((int *)(*stack)->content); + const int b = *((int *)(*stack)->next->content); + const int c = *((int *)(*stack)->next->next->content); + + if (ft_lstsize(*stack) != 3) + return (0); + if (a < b && b < c) + return (1); + else if (a < b && b > c) + { + rra(); + if (a > b) + sa(); + } + else if (a > c && b < c) + ra(); + else + { + sa(); + if (b > c) + rra(); + } + return (1); +} diff --git a/src/util/new_element.c b/src/util/new_element.c index a13fbac..65ace93 100644 --- a/src/util/new_element.c +++ b/src/util/new_element.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/11/06 19:19:32 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/11/06 19:37:28 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/11/07 13:18:48 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */