From 5372b944a4bb83bc9ea0dd91d6d4834100a2cbba Mon Sep 17 00:00:00 2001 From: Maoake Date: Wed, 10 Dec 2025 21:02:33 +0000 Subject: [PATCH] adding makefile and debugging to try new test for the preset to test the program --- Makefile | 50 ++++++++++++++++++++++ algorithms/medium_utils/utils_medium.c | 12 +++--- algorithms/medium_utils/utils_struct_tab.c | 13 +++--- algorithms/utils/compare_value.c | 2 +- push_swap.h | 13 +++--- stack_utils/push.c | 2 +- stack_utils/rev_rotate.c | 2 +- stack_utils/rotate.c | 2 +- stack_utils/stack_add.c | 2 +- stack_utils/stack_remove.c | 2 +- stack_utils/swap.c | 2 +- 11 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eeaafd6 --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +SRC = main.c ft_atoi.c parsing.c + +STACK_UTILS = stack_utils/push.c stack_utils/rev_rotate.c stack_utils/rotate.c \ + stack_utils/stack_add.c stack_utils/stack_remove.c stack_utils/swap.c + +MEDIUM_ALGO = algorithms/medium_algo.c algorithms/medium_utils/utils_medium.c \ + algorithms/medium_utils/utils_struct_tab.c + +ALGO_UTILS = algorithms/utils/check_order.c algorithms/utils/compare_value.c \ + algorithms/utils/stack_len.c + +ALL_FILES = $(SRC) $(STACK_UTILS) $(MEDIUM_ALGO) $(ALGO_UTILS) + +OBJ_DIR = obj + +CC = cc + +CFLAGS = -Wall -Werror -Wextra -I. + +NAME = push_swap + +OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(ALL_FILES:.c=.o))) + +DEP = $(OBJ:.o=.d) + +.PHONY: all clean fclean re + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(CFLAGS) $(OBJ) -o $(NAME) + +$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR) + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ + +$(OBJ_DIR): + @mkdir -p $(OBJ_DIR) + +clean: + @rm -rf $(OBJ_DIR) + @echo "====================================" + @echo "= ALL OBJECT AND DEPENDENCES CLEAN =" + @echo "====================================" + +fclean: clean + rm -f $(NAME) + +re: fclean all + +-include $(DEP) \ No newline at end of file diff --git a/algorithms/medium_utils/utils_medium.c b/algorithms/medium_utils/utils_medium.c index 6e6e185..7156c01 100644 --- a/algorithms/medium_utils/utils_medium.c +++ b/algorithms/medium_utils/utils_medium.c @@ -34,14 +34,14 @@ int get_next_lower(t_stack *first, int old_lower) int next_lower; tmp = first; - lower = tmp->value; + next_lower = tmp->value; while (tmp->next != first) { - if (tmp->value != old_lower && lower < tmp->value) - lower = tmp->value; + if (tmp->value != old_lower && next_lower < tmp->value) + next_lower = tmp->value; tmp = tmp->next; } - return (lower); + return (next_lower); } int calcul_range(int value, int range) @@ -70,14 +70,14 @@ int in_range(int value, int max_range) return (0); } -int get_number_in_range(int range, t_stacks *piles) +int get_number_in_range(int range, t_stack *a) { int nb_in; t_stack *tmp; t_stack *first; nb_in = 0; - tmp = piles->a; + tmp = a; first = tmp; while (tmp->next != first) { diff --git a/algorithms/medium_utils/utils_struct_tab.c b/algorithms/medium_utils/utils_struct_tab.c index d3b0af8..7d5caa0 100644 --- a/algorithms/medium_utils/utils_struct_tab.c +++ b/algorithms/medium_utils/utils_struct_tab.c @@ -11,15 +11,16 @@ /* ************************************************************************** */ #include "push_swap.h" +#include t_tab *allocate_tab(int range_max, int nb) { - t_tab tab; + t_tab *tab; tab = malloc(sizeof(t_tab)); if (!tab) return (NULL); - tab->range_max = range_max; + tab->max_range = range_max; tab->nb_in = nb; return (tab); } @@ -32,10 +33,10 @@ t_tab *get_tabs(t_stack *first) int scan_nb_in_tab; len_stack = stack_len(first); - first_tab = first_tab(first); + first_tab = init_first_tab(first); if (!first_tab) return (NULL); - scan_nb_in_tab = tab->nb_in; + scan_nb_in_tab = first_tab->nb_in; tmp = first_tab; while (scan_nb_in_tab < len_stack) { @@ -48,7 +49,7 @@ t_tab *get_tabs(t_stack *first) return (first_tab); } -t_tab *first_tab(t_stack *first) +t_tab *init_first_tab(t_stack *first) { t_tab *tab; int lower; @@ -62,7 +63,7 @@ t_tab *first_tab(t_stack *first) return (tab); } -t_tab *get_next_tab(t_stack *first, t_tab tab) +t_tab *get_next_tab(t_stack *first, t_tab *tab) { int lower; int range_max; diff --git a/algorithms/utils/compare_value.c b/algorithms/utils/compare_value.c index 47f2dcf..38d8db0 100644 --- a/algorithms/utils/compare_value.c +++ b/algorithms/utils/compare_value.c @@ -12,7 +12,7 @@ #include "push_swap.h" -int is_upper_compare(t_stack t1, t_stack t2) +int is_upper_compare(t_stack *t1, t_stack *t2) { if (t1->value > t2->value) return (1); diff --git a/push_swap.h b/push_swap.h index b4cb81b..fa6482a 100644 --- a/push_swap.h +++ b/push_swap.h @@ -28,7 +28,7 @@ typedef struct s_stacks typedef struct s_tab { - int range_max; + int max_range; int nb_in; struct s_tab *next; } t_tab; @@ -53,17 +53,20 @@ void stack_clear_all(t_stack *stack, t_stack *first); t_stack *parsing(int argc, char **argv); t_stacks *init_big_stacks(int argc, char **argv); int ft_atoi(const char *nptr); +/*FUNCTION UTILS ALGO*/ +int check_order(t_stack *stack); +int is_upper_compare(t_stack *t1, t_stack *t2); +int stack_len(t_stack *stack); /*FUNCTION FOR MEDIUM ALGO*/ t_tab *get_tabs(t_stack *first); -int get_number_in_range(int range, t_stacks *piles); +int get_number_in_range(int range, t_stack *a); int in_range(int value, int max_range); int calcul_range(int value, int range); int get_next_lower(t_stack *first, int old_lower); int get_first_lower(t_stack *first); -int is_upper_compare(t_stack t1, t_stack t2); t_tab *free_tab(t_tab *first); -t_tab *get_next_tab(t_stack *first, t_tab tab); -t_tab *first_tab(t_stack *first); +t_tab *get_next_tab(t_stack *first, t_tab *tab); +t_tab *init_first_tab(t_stack *first); t_tab *allocate_tab(int range_max, int nb); #endif diff --git a/stack_utils/push.c b/stack_utils/push.c index 1c43f79..1c8d42a 100644 --- a/stack_utils/push.c +++ b/stack_utils/push.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" #include void pa(t_stacks *stacks) diff --git a/stack_utils/rev_rotate.c b/stack_utils/rev_rotate.c index a8aca03..659ca4c 100644 --- a/stack_utils/rev_rotate.c +++ b/stack_utils/rev_rotate.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" void rra(t_stacks *stacks) { diff --git a/stack_utils/rotate.c b/stack_utils/rotate.c index d2ce509..8830823 100644 --- a/stack_utils/rotate.c +++ b/stack_utils/rotate.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" void ra(t_stacks *stacks) { diff --git a/stack_utils/stack_add.c b/stack_utils/stack_add.c index 761143a..fd945d2 100644 --- a/stack_utils/stack_add.c +++ b/stack_utils/stack_add.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" #include t_stack *new_stack(int value) diff --git a/stack_utils/stack_remove.c b/stack_utils/stack_remove.c index 2c53bf8..16a7dce 100644 --- a/stack_utils/stack_remove.c +++ b/stack_utils/stack_remove.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" #include void stack_clear_all(t_stack *stack, t_stack *first) diff --git a/stack_utils/swap.c b/stack_utils/swap.c index 61fbb6b..e8a31a3 100644 --- a/stack_utils/swap.c +++ b/stack_utils/swap.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../push_swap.h" +#include "push_swap.h" void sa(t_stacks *stacks) {