From 0df082065e549c59b3111f42dae4c40ae15a26ac Mon Sep 17 00:00:00 2001 From: Maoake Teriierooiterai Date: Thu, 8 Jan 2026 19:02:13 +0100 Subject: [PATCH] finish the parsing solve the problem with 2 arg --- algorithms/utils/pre_sort.c | 5 +++++ flags/algorithms_sort.c | 13 ++++++++++--- headers/push_swap.h | 1 + test_one.c | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/algorithms/utils/pre_sort.c b/algorithms/utils/pre_sort.c index 46459a1..74656a3 100644 --- a/algorithms/utils/pre_sort.c +++ b/algorithms/utils/pre_sort.c @@ -35,6 +35,11 @@ int r_to_lowest(t_stack *stack, int len) return (lowest_i); } +void sort_two(t_stacks *stacks) +{ + sa(stacks); +} + void sort_three_a(t_stacks *stacks) { if (check_order(stacks->a)) diff --git a/flags/algorithms_sort.c b/flags/algorithms_sort.c index a5d1ac5..117b240 100644 --- a/flags/algorithms_sort.c +++ b/flags/algorithms_sort.c @@ -26,11 +26,18 @@ void medium(t_stacks *piles) { t_tab *buckets; int range; + int len; piles->algo = 2; - range = range_bucket(piles->a); - buckets = get_tabs(piles->a, range); - bucket_algo(piles, buckets, range); + len = stack_a_len(piles); + if (len == 2) + sort_two(piles); + else + { + range = range_bucket(piles->a); + buckets = get_tabs(piles->a, range); + bucket_algo(piles, buckets, range); + } } void complex(t_stacks *piles) diff --git a/headers/push_swap.h b/headers/push_swap.h index e83c07b..d1173a6 100644 --- a/headers/push_swap.h +++ b/headers/push_swap.h @@ -67,6 +67,7 @@ int highest_stack_len(t_stacks *stacks); /* PRE SORT */ int r_to_lowest(t_stack *stack, int len); void sort_three_a(t_stacks *stacks); +void sort_two(t_stacks *stacks); /* ITERATE FILE */ void optimal_rotate(t_stacks *stacks, int i, int len, char stack); /* COMPARE FILE */ diff --git a/test_one.c b/test_one.c index 89cac2c..3b73465 100644 --- a/test_one.c +++ b/test_one.c @@ -25,6 +25,8 @@ int test1(int argc, char **argv) piles = NULL; mod = calcul_mod(argc, argv); piles = init_piles(argc, argv, mod); + if (check_order(piles->a)) + return (0); flags(pos_flag(argv, mod), pos_bench(argv, mod), argv, piles); if (piles->bench == 1) print_bench(piles);