adding makefile and debugging to try new test for the preset to test the program

This commit is contained in:
Maoake
2025-12-10 21:02:33 +00:00
parent b6c1dc73a8
commit 5372b944a4
11 changed files with 78 additions and 24 deletions

50
Makefile Normal file
View File

@@ -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)

View File

@@ -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)
{

View File

@@ -11,15 +11,16 @@
/* ************************************************************************** */
#include "push_swap.h"
#include <stdlib.h>
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;

View File

@@ -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);

View File

@@ -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

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
#include <stdlib.h>
void pa(t_stacks *stacks)

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
void rra(t_stacks *stacks)
{

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
void ra(t_stacks *stacks)
{

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
#include <stdlib.h>
t_stack *new_stack(int value)

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
#include <stdlib.h>
void stack_clear_all(t_stack *stack, t_stack *first)

View File

@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include "push_swap.h"
void sa(t_stacks *stacks)
{