mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Not working radix
This commit is contained in:
11
Makefile
11
Makefile
@@ -14,6 +14,8 @@ PARS_DIR = parsing
|
|||||||
|
|
||||||
MEDIUM_DIR = medium
|
MEDIUM_DIR = medium
|
||||||
|
|
||||||
|
COMPLEX_DIR = radix
|
||||||
|
|
||||||
INCLUDES = headers
|
INCLUDES = headers
|
||||||
|
|
||||||
#============================
|
#============================
|
||||||
@@ -30,6 +32,8 @@ STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len
|
|||||||
|
|
||||||
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c
|
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c
|
||||||
|
|
||||||
|
COMPLEX_ALGO = radix.c
|
||||||
|
|
||||||
ALGO_UTILS = check_order.c compare.c iterate.c pre_sort.c
|
ALGO_UTILS = check_order.c compare.c iterate.c pre_sort.c
|
||||||
|
|
||||||
#============================
|
#============================
|
||||||
@@ -38,7 +42,7 @@ ALGO_UTILS = check_order.c compare.c iterate.c pre_sort.c
|
|||||||
|
|
||||||
ALL_FILES = $(SRC) $(STACK_UTILS_DIR)/$(STACK_UTILS) $(PARS_DIR)/$(PARSING) \
|
ALL_FILES = $(SRC) $(STACK_UTILS_DIR)/$(STACK_UTILS) $(PARS_DIR)/$(PARSING) \
|
||||||
$(ALGO_DIR)/$(MEDIUM_DIR)/$(MEDIUM_ALGO) $(ALGO_UTILS_DIR)/$(ALGO_UTILS) \
|
$(ALGO_DIR)/$(MEDIUM_DIR)/$(MEDIUM_ALGO) $(ALGO_UTILS_DIR)/$(ALGO_UTILS) \
|
||||||
$(INSERT_DIR)/$(INSERTION)
|
$(INSERT_DIR)/$(INSERTION) $(ALGO_DIR)/$(COMPLEX_DIR)/$(COMPLEX_ALGO)
|
||||||
|
|
||||||
OBJ_DIR = obj
|
OBJ_DIR = obj
|
||||||
|
|
||||||
@@ -79,6 +83,9 @@ $(OBJ_DIR)/%.o: $(ALGO_DIR)/%.c | $(OBJ_DIR)
|
|||||||
$(OBJ_DIR)/%.o: $(ALGO_DIR)/$(MEDIUM_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(ALGO_DIR)/$(MEDIUM_DIR)/%.c | $(OBJ_DIR)
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(ALGO_DIR)/$(COMPLEX_DIR)/%.c | $(OBJ_DIR)
|
||||||
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(ALGO_UTILS_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(ALGO_UTILS_DIR)/%.c | $(OBJ_DIR)
|
||||||
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
@@ -98,4 +105,4 @@ fclean: clean
|
|||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
-include $(DEP)
|
-include $(DEP)
|
||||||
|
|||||||
92
algorithms/radix/radix.c
Normal file
92
algorithms/radix/radix.c
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* radix.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/06 12:47:06 by dgaillet #+# #+# */
|
||||||
|
/* Updated: 2026/01/07 11:45:50 by dgaillet ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
/*
|
||||||
|
static int one_higher_than_unit(t_stack *stack, int unit)
|
||||||
|
{
|
||||||
|
t_stack *temp;
|
||||||
|
|
||||||
|
temp = stack;
|
||||||
|
if (stack->value > unit)
|
||||||
|
return (1);
|
||||||
|
stack = stack->next;
|
||||||
|
while (stack != temp)
|
||||||
|
{
|
||||||
|
if (stack->value > unit)
|
||||||
|
return (1);
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
static int to_insert(t_stacks *stacks, int value)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int s_len;
|
||||||
|
t_stack *temp;
|
||||||
|
|
||||||
|
temp = stacks->a;
|
||||||
|
if (!stacks->a)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
s_len = stack_a_len(stacks);
|
||||||
|
while (temp->value < value
|
||||||
|
&& temp->previous->value > value && s_len >= i)
|
||||||
|
{
|
||||||
|
if (s_len == i)
|
||||||
|
return (r_to_lowest(stacks->a, s_len) + 1);
|
||||||
|
i++;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_contain_lower_unit(t_stack *stack, int unit, int s_len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < s_len)
|
||||||
|
{
|
||||||
|
if (stack->value < unit)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rec_sort(t_stacks *stacks, int unit)
|
||||||
|
{
|
||||||
|
if (!stacks->b)
|
||||||
|
return ;
|
||||||
|
while (is_contain_lower_unit(stacks->b, unit, stack_b_len(stacks)))
|
||||||
|
{
|
||||||
|
if (stacks->b->value < unit)
|
||||||
|
{
|
||||||
|
optimal_rotate(stacks, to_insert(stacks, stacks->b->value)
|
||||||
|
, stack_a_len(stacks), 'a');
|
||||||
|
pa(stacks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rb(stacks);
|
||||||
|
}
|
||||||
|
rec_sort(stacks, unit * 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void radix(t_stacks *stacks)
|
||||||
|
{
|
||||||
|
while (stacks->a)
|
||||||
|
pb(stacks);
|
||||||
|
rec_sort(stacks, 10);
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
|
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
|
||||||
/* Updated: 2025/12/15 14:34:45 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/07 10:30:42 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -65,4 +65,7 @@ int test2(char **argv);
|
|||||||
/* TEST FILE */
|
/* TEST FILE */
|
||||||
int test1(int argc, char **argv);
|
int test1(int argc, char **argv);
|
||||||
|
|
||||||
|
/* RADIX */
|
||||||
|
void radix(t_stacks *stacks);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
|
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/22 12:33:58 by mteriier #+# #+# */
|
/* Created: 2025/12/22 12:33:58 by mteriier #+# #+# */
|
||||||
/* Updated: 2025/12/22 12:34:35 by mteriier ### ########.fr */
|
/* Updated: 2026/01/07 10:49:03 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,14 +19,15 @@
|
|||||||
int test1(int argc, char **argv)
|
int test1(int argc, char **argv)
|
||||||
{
|
{
|
||||||
t_stacks *piles;
|
t_stacks *piles;
|
||||||
t_tab *preset;
|
//t_tab *preset;
|
||||||
|
|
||||||
piles = NULL;
|
piles = NULL;
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
piles = init_big_stacks(argc, argv);
|
piles = init_big_stacks(argc, argv);
|
||||||
preset = get_tabs(piles->a, range_bucket(piles->a));
|
//preset = get_tabs(piles->a, range_bucket(piles->a));
|
||||||
bucket_algo(piles, preset, range_bucket(piles->a));
|
//bucket_algo(piles, preset, range_bucket(piles->a));
|
||||||
|
radix(piles);
|
||||||
}
|
}
|
||||||
if (piles->a)
|
if (piles->a)
|
||||||
stack_clear_all(piles->a, piles->a);
|
stack_clear_all(piles->a, piles->a);
|
||||||
|
|||||||
Reference in New Issue
Block a user