mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
adding makefile and debugging to try new test for the preset to test the program
This commit is contained in:
50
Makefile
Normal file
50
Makefile
Normal 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)
|
||||||
@@ -34,14 +34,14 @@ int get_next_lower(t_stack *first, int old_lower)
|
|||||||
int next_lower;
|
int next_lower;
|
||||||
|
|
||||||
tmp = first;
|
tmp = first;
|
||||||
lower = tmp->value;
|
next_lower = tmp->value;
|
||||||
while (tmp->next != first)
|
while (tmp->next != first)
|
||||||
{
|
{
|
||||||
if (tmp->value != old_lower && lower < tmp->value)
|
if (tmp->value != old_lower && next_lower < tmp->value)
|
||||||
lower = tmp->value;
|
next_lower = tmp->value;
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
return (lower);
|
return (next_lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
int calcul_range(int value, int range)
|
int calcul_range(int value, int range)
|
||||||
@@ -70,14 +70,14 @@ int in_range(int value, int max_range)
|
|||||||
return (0);
|
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;
|
int nb_in;
|
||||||
t_stack *tmp;
|
t_stack *tmp;
|
||||||
t_stack *first;
|
t_stack *first;
|
||||||
|
|
||||||
nb_in = 0;
|
nb_in = 0;
|
||||||
tmp = piles->a;
|
tmp = a;
|
||||||
first = tmp;
|
first = tmp;
|
||||||
while (tmp->next != first)
|
while (tmp->next != first)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,15 +11,16 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
t_tab *allocate_tab(int range_max, int nb)
|
t_tab *allocate_tab(int range_max, int nb)
|
||||||
{
|
{
|
||||||
t_tab tab;
|
t_tab *tab;
|
||||||
|
|
||||||
tab = malloc(sizeof(t_tab));
|
tab = malloc(sizeof(t_tab));
|
||||||
if (!tab)
|
if (!tab)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
tab->range_max = range_max;
|
tab->max_range = range_max;
|
||||||
tab->nb_in = nb;
|
tab->nb_in = nb;
|
||||||
return (tab);
|
return (tab);
|
||||||
}
|
}
|
||||||
@@ -32,10 +33,10 @@ t_tab *get_tabs(t_stack *first)
|
|||||||
int scan_nb_in_tab;
|
int scan_nb_in_tab;
|
||||||
|
|
||||||
len_stack = stack_len(first);
|
len_stack = stack_len(first);
|
||||||
first_tab = first_tab(first);
|
first_tab = init_first_tab(first);
|
||||||
if (!first_tab)
|
if (!first_tab)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
scan_nb_in_tab = tab->nb_in;
|
scan_nb_in_tab = first_tab->nb_in;
|
||||||
tmp = first_tab;
|
tmp = first_tab;
|
||||||
while (scan_nb_in_tab < len_stack)
|
while (scan_nb_in_tab < len_stack)
|
||||||
{
|
{
|
||||||
@@ -48,7 +49,7 @@ t_tab *get_tabs(t_stack *first)
|
|||||||
return (first_tab);
|
return (first_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_tab *first_tab(t_stack *first)
|
t_tab *init_first_tab(t_stack *first)
|
||||||
{
|
{
|
||||||
t_tab *tab;
|
t_tab *tab;
|
||||||
int lower;
|
int lower;
|
||||||
@@ -62,7 +63,7 @@ t_tab *first_tab(t_stack *first)
|
|||||||
return (tab);
|
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 lower;
|
||||||
int range_max;
|
int range_max;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "push_swap.h"
|
#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)
|
if (t1->value > t2->value)
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
13
push_swap.h
13
push_swap.h
@@ -28,7 +28,7 @@ typedef struct s_stacks
|
|||||||
|
|
||||||
typedef struct s_tab
|
typedef struct s_tab
|
||||||
{
|
{
|
||||||
int range_max;
|
int max_range;
|
||||||
int nb_in;
|
int nb_in;
|
||||||
struct s_tab *next;
|
struct s_tab *next;
|
||||||
} t_tab;
|
} t_tab;
|
||||||
@@ -53,17 +53,20 @@ void stack_clear_all(t_stack *stack, t_stack *first);
|
|||||||
t_stack *parsing(int argc, char **argv);
|
t_stack *parsing(int argc, char **argv);
|
||||||
t_stacks *init_big_stacks(int argc, char **argv);
|
t_stacks *init_big_stacks(int argc, char **argv);
|
||||||
int ft_atoi(const char *nptr);
|
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*/
|
/*FUNCTION FOR MEDIUM ALGO*/
|
||||||
t_tab *get_tabs(t_stack *first);
|
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 in_range(int value, int max_range);
|
||||||
int calcul_range(int value, int range);
|
int calcul_range(int value, int range);
|
||||||
int get_next_lower(t_stack *first, int old_lower);
|
int get_next_lower(t_stack *first, int old_lower);
|
||||||
int get_first_lower(t_stack *first);
|
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 *free_tab(t_tab *first);
|
||||||
t_tab *get_next_tab(t_stack *first, t_tab tab);
|
t_tab *get_next_tab(t_stack *first, t_tab *tab);
|
||||||
t_tab *first_tab(t_stack *first);
|
t_tab *init_first_tab(t_stack *first);
|
||||||
t_tab *allocate_tab(int range_max, int nb);
|
t_tab *allocate_tab(int range_max, int nb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void pa(t_stacks *stacks)
|
void pa(t_stacks *stacks)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
void rra(t_stacks *stacks)
|
void rra(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
void ra(t_stacks *stacks)
|
void ra(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
t_stack *new_stack(int value)
|
t_stack *new_stack(int value)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void stack_clear_all(t_stack *stack, t_stack *first)
|
void stack_clear_all(t_stack *stack, t_stack *first)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
void sa(t_stacks *stacks)
|
void sa(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user