From 854d6997805cf064f1f636a99c7e31719e422987 Mon Sep 17 00:00:00 2001 From: Maoake Teriierooiterai Date: Thu, 15 Jan 2026 11:39:32 +0100 Subject: [PATCH] modifying some folders --- Makefile | 2 +- algorithms/medium/medium_algo.c | 16 +++++------ algorithms/medium/sort_utils_two.c | 46 ++++++++++++++++++++++++++++++ includes/medium_headers.h | 2 ++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index d9f4608..ec4d91c 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ NAME_BONUS = checker .PHONY: all clean fclean re bonus -all: $(NAME) +all: $(NAME) $(NAME_BONUS) $(NAME): $(OBJ) @$(CC) $(CFLAGS) $(OBJ) -o $(NAME) diff --git a/algorithms/medium/medium_algo.c b/algorithms/medium/medium_algo.c index 4d020ce..2de20a1 100644 --- a/algorithms/medium/medium_algo.c +++ b/algorithms/medium/medium_algo.c @@ -13,7 +13,7 @@ #include "push_swap.h" #include "medium_headers.h" #include - +#include static int path_to_end(t_stacks *stacks, int max_range, int range, char c) { t_stack *tmp; @@ -41,21 +41,20 @@ static int path_to_end(t_stacks *stacks, int max_range, int range, char c) static int path_to_start(t_stacks *stacks, int max_range, int range, char c) { t_stack *tmp; + t_stack *start; int i; int first_pass; - if (c == 'a') - tmp = stacks->a; - else - tmp = stacks->b; + tmp = (stacks, c); + start = (stacks, c); i = 0; first_pass = 1; - while (first_pass || tmp != stacks->b) + while (first_pass || tmp != start) { first_pass = 0; if (in_range(tmp->value, max_range, range)) { - tmp = stacks->b->previous; + tmp = start->previous; } tmp = tmp->next; i++; @@ -95,8 +94,7 @@ void bucket_algo(t_stacks *stacks, t_tab *preset, int range) t_tab *tmp; tmp = preset; - while (stacks->a) - pb(stacks); + medium_pre_sort(stacks, preset, range); while (preset) { push_range_to_b(stacks, preset, range); diff --git a/algorithms/medium/sort_utils_two.c b/algorithms/medium/sort_utils_two.c index a77d2d4..c209c3d 100644 --- a/algorithms/medium/sort_utils_two.c +++ b/algorithms/medium/sort_utils_two.c @@ -11,6 +11,41 @@ /* ************************************************************************** */ #include "push_swap.h" +#include "medium_headers.h" + +static void medium_pus_to_a(t_stacks *stacks, t_tab *one_preset, int range) +{ + int i; + + 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)) + ra(stacks); + } + else + { + 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; + + tmp = preset; + while (preset) + { + medium_pus_to_a(stacks, tmp, range); + tmp = tmp->next; + } +} void sort_from_left(t_stacks *stacks) { @@ -47,3 +82,14 @@ void sort_from_right(t_stacks *stacks) i--; } } + +t_stack *assign_stack(t_stacks *stacks, char c) +{ + t_stack *tmp; + + if (c == 'a') + tmp = stacks->a; + else + tmp = stacks->b; + return (tmp); +} diff --git a/includes/medium_headers.h b/includes/medium_headers.h index f7ac7c3..4def295 100644 --- a/includes/medium_headers.h +++ b/includes/medium_headers.h @@ -28,6 +28,8 @@ void bucket_algo(t_stacks *stacks, t_tab *preset, int range); void sort_from_left(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 medium_pre_sort(t_stacks *stacks, t_tab *preset, int range); +t_stack *assign_stack(t_stacks *stacks, char c); /* MEDIUM UTILS FILES */ int range_bucket(t_stack *first); int get_first_lower(t_stack *first);