mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Radix is woking
This commit is contained in:
2
Makefile
2
Makefile
@@ -52,7 +52,7 @@ OBJ_DIR = obj
|
|||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
||||||
CFLAGS = -Wall -Werror -Wextra -I$(INCLUDES)
|
CFLAGS = -Wall -Werror -Wextra -g3 -I$(INCLUDES)
|
||||||
|
|
||||||
NAME = push_swap
|
NAME = push_swap
|
||||||
|
|
||||||
|
|||||||
@@ -6,87 +6,71 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/01/06 12:47:06 by dgaillet #+# #+# */
|
/* Created: 2026/01/06 12:47:06 by dgaillet #+# #+# */
|
||||||
/* Updated: 2026/01/07 11:45:50 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/07 16:19:37 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
/*
|
|
||||||
static int one_higher_than_unit(t_stack *stack, int unit)
|
static int still_unit_value(t_stacks *stacks, int unit)
|
||||||
{
|
{
|
||||||
t_stack *temp;
|
t_stack *temp;
|
||||||
|
|
||||||
temp = stack;
|
temp = stacks->a;
|
||||||
if (stack->value > unit)
|
if (temp->value >= unit)
|
||||||
return (1);
|
return (1);
|
||||||
stack = stack->next;
|
temp = temp->next;
|
||||||
while (stack != temp)
|
while (temp != stacks->a)
|
||||||
{
|
{
|
||||||
if (stack->value > unit)
|
if (temp->value >= unit)
|
||||||
return (1);
|
return (1);
|
||||||
stack = stack->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
static int to_insert(t_stacks *stacks, int value)
|
static void push_by_number_to_b(t_stacks *stacks, int unit, int nb)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int s_len;
|
int s_len;
|
||||||
t_stack *temp;
|
t_stack *temp;
|
||||||
|
|
||||||
temp = stacks->a;
|
temp = stacks->a;
|
||||||
if (!stacks->a)
|
s_len = 1;
|
||||||
return (0);
|
while (temp && temp->next != stacks->a)
|
||||||
i = 0;
|
|
||||||
s_len = stack_a_len(stacks);
|
|
||||||
while (temp->value < value
|
|
||||||
&& temp->previous->value > value && s_len >= i)
|
|
||||||
{
|
{
|
||||||
if (s_len == i)
|
s_len++;
|
||||||
return (r_to_lowest(stacks->a, s_len) + 1);
|
|
||||||
i++;
|
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_contain_lower_unit(t_stack *stack, int unit, int s_len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < s_len)
|
while (i < s_len && still_unit_value(stacks, unit))
|
||||||
{
|
{
|
||||||
if (stack->value < unit)
|
if (stacks->a && (stacks->a->value % (unit * 10)) / unit == nb)
|
||||||
return (1);
|
pb(stacks);
|
||||||
|
else
|
||||||
|
ra(stacks);
|
||||||
i++;
|
i++;
|
||||||
stack = stack->next;
|
|
||||||
}
|
}
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rec_sort(t_stacks *stacks, int unit)
|
static void rec_sort(t_stacks *stacks, int unit)
|
||||||
{
|
{
|
||||||
if (!stacks->b)
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!still_unit_value(stacks, unit))
|
||||||
return ;
|
return ;
|
||||||
while (is_contain_lower_unit(stacks->b, unit, stack_b_len(stacks)))
|
while (i <= 9)
|
||||||
{
|
{
|
||||||
if (stacks->b->value < unit)
|
push_by_number_to_b(stacks, unit, i);
|
||||||
{
|
i++;
|
||||||
optimal_rotate(stacks, to_insert(stacks, stacks->b->value)
|
|
||||||
, stack_a_len(stacks), 'a');
|
|
||||||
pa(stacks);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
rb(stacks);
|
|
||||||
}
|
}
|
||||||
|
while (stacks->b)
|
||||||
|
pa(stacks);
|
||||||
rec_sort(stacks, unit * 10);
|
rec_sort(stacks, unit * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void radix(t_stacks *stacks)
|
void radix(t_stacks *stacks)
|
||||||
{
|
{
|
||||||
while (stacks->a)
|
rec_sort(stacks, 1);
|
||||||
pb(stacks);
|
|
||||||
rec_sort(stacks, 10);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: 2026/01/07 10:49:03 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/07 14:58:10 by dgaillet ### ########lyon.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -30,6 +30,6 @@ int test1(int argc, char **argv)
|
|||||||
radix(piles);
|
radix(piles);
|
||||||
}
|
}
|
||||||
free_all(piles);
|
free_all(piles);
|
||||||
free(piles);
|
//free(piles);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user