trying some opti start to opti

This commit is contained in:
Maoake Teriierooiterai
2026-01-15 12:09:38 +01:00
parent 854d699780
commit 469320374d
5 changed files with 22 additions and 51 deletions

View File

@@ -93,7 +93,7 @@ NAME_BONUS = checker
.PHONY: all clean fclean re bonus .PHONY: all clean fclean re bonus
all: $(NAME) $(NAME_BONUS) all: $(NAME)
$(NAME): $(OBJ) $(NAME): $(OBJ)
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME) @$(CC) $(CFLAGS) $(OBJ) -o $(NAME)

View File

@@ -13,25 +13,24 @@
#include "push_swap.h" #include "push_swap.h"
#include "medium_headers.h" #include "medium_headers.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
static int path_to_end(t_stacks *stacks, int max_range, int range, char c) static int path_to_end(t_stacks *stacks, int max_range, int range, char c)
{ {
t_stack *tmp; t_stack *tmp;
t_stack *start;
int i; int i;
int first_pass; int first_pass;
if (c == 'a') tmp = assign_stack(stacks, c);
tmp = stacks->a; start = assign_stack(stacks, c);
else
tmp = stacks->b;
tmp = tmp->previous; tmp = tmp->previous;
i = 0; i = 0;
first_pass = 1; first_pass = 1;
while (first_pass || tmp != stacks->b->previous) while (first_pass || tmp != start->previous)
{ {
first_pass = 0; first_pass = 0;
if (in_range(tmp->value, max_range, range)) if (in_range(tmp->value, max_range, range))
tmp = stacks->b; tmp = start;
tmp = tmp->previous; tmp = tmp->previous;
i++; i++;
} }
@@ -45,8 +44,8 @@ static int path_to_start(t_stacks *stacks, int max_range, int range, char c)
int i; int i;
int first_pass; int first_pass;
tmp = (stacks, c); tmp = assign_stack(stacks, c);
start = (stacks, c); start = assign_stack(stacks, c);
i = 0; i = 0;
first_pass = 1; first_pass = 1;
while (first_pass || tmp != start) while (first_pass || tmp != start)
@@ -94,7 +93,8 @@ void bucket_algo(t_stacks *stacks, t_tab *preset, int range)
t_tab *tmp; t_tab *tmp;
tmp = preset; tmp = preset;
medium_pre_sort(stacks, preset, range); while(stacks->a)
pb(stacks);
while (preset) while (preset)
{ {
push_range_to_b(stacks, preset, range); push_range_to_b(stacks, preset, range);

View File

@@ -77,18 +77,7 @@ void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range)
{ {
while (one_preset->nb_in > 0) while (one_preset->nb_in > 0)
{ {
if (wich_path(stacks, one_preset->max_range, range, 'b')) normal_move_path(stacks, one_preset, range);
{
while (!in_range(stacks->b->value, one_preset->max_range, range))
rb(stacks);
}
else
{
while (!in_range(stacks->b->value, one_preset->max_range, range))
{
rrb(stacks);
}
}
sort_little_pile(stacks); sort_little_pile(stacks);
one_preset->nb_in--; one_preset->nb_in--;
} }

View File

@@ -13,37 +13,19 @@
#include "push_swap.h" #include "push_swap.h"
#include "medium_headers.h" #include "medium_headers.h"
static void medium_pus_to_a(t_stacks *stacks, t_tab *one_preset, int range) void normal_move_path(t_stacks *stacks, t_tab *one_preset, int range)
{ {
int i; if (wich_path(stacks, one_preset->max_range, range, 'b'))
i = 0;
while (one_preset->nb_in > i)
{
if (wich_path(stacks, one_preset->max_range, range, 'a'))
{ {
while (!in_range(stacks->b->value, one_preset->max_range, range)) while (!in_range(stacks->b->value, one_preset->max_range, range))
ra(stacks); rb(stacks);
} }
else else
{ {
while (!in_range(stacks->b->value, one_preset->max_range, range)) while (!in_range(stacks->b->value, one_preset->max_range, range))
rra(stacks);
}
pb(stacks);
i++;
}
}
void medium_pre_sort(t_stacks *stacks, t_tab *preset, int range)
{ {
t_tab *tmp; rrb(stacks);
}
tmp = preset;
while (preset)
{
medium_pus_to_a(stacks, tmp, range);
tmp = tmp->next;
} }
} }

View File

@@ -28,7 +28,7 @@ void bucket_algo(t_stacks *stacks, t_tab *preset, int range);
void sort_from_left(t_stacks *stacks); void sort_from_left(t_stacks *stacks);
void sort_from_right(t_stacks *stacks); void sort_from_right(t_stacks *stacks);
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range); void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range);
void medium_pre_sort(t_stacks *stacks, t_tab *preset, int range); void normal_move_path(t_stacks *stacks, t_tab *one_preset, int range);
t_stack *assign_stack(t_stacks *stacks, char c); t_stack *assign_stack(t_stacks *stacks, char c);
/* MEDIUM UTILS FILES */ /* MEDIUM UTILS FILES */
int range_bucket(t_stack *first); int range_bucket(t_stack *first);