Skip to content

Commit

Permalink
refacotr _handle_5 with 2 flows
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Jan 17, 2024
1 parent d5f2a62 commit 2a55ee2
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/sort/micro_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 16:32:27 by reasuke #+# #+# */
/* Updated: 2024/01/17 18:28:00 by reasuke ### ########.fr */
/* Updated: 2024/01/17 18:33:18 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,22 +37,17 @@ static void _handle_4(t_list **stack_a, t_list **stack_b)
}
}

static void _handle_5(t_list **stack_a, t_list **stack_b)
static void _edge_flow_5(t_list **stack_a, t_list **stack_b)
{
operate_pb(stack_a, stack_b);
operate_pb(stack_a, stack_b);
nano_sort(stack_a, 3);
if (first_content(stack_b) < second_content(stack_b))
operate_sb(stack_b);
if (first_content(stack_b) == 5 && second_content(stack_b) == 4)
{
operate_pa(stack_b, stack_a);
operate_pa(stack_b, stack_a);
operate_ra(stack_a);
operate_ra(stack_a);
return ;
}
else if (first_content(stack_b) == 5)
operate_pa(stack_b, stack_a);
operate_pa(stack_b, stack_a);
operate_ra(stack_a);
operate_ra(stack_a);
}

static void _normal_flow_5(t_list **stack_a, t_list **stack_b)
{
if (first_content(stack_b) == 5)
{
operate_pa(stack_b, stack_a);
operate_rra(stack_a);
Expand All @@ -70,6 +65,19 @@ static void _handle_5(t_list **stack_a, t_list **stack_b)
operate_rra(stack_a);
}

static void _handle_5(t_list **stack_a, t_list **stack_b)
{
operate_pb(stack_a, stack_b);
operate_pb(stack_a, stack_b);
nano_sort(stack_a, 3);
if (first_content(stack_b) < second_content(stack_b))
operate_sb(stack_b);
if (first_content(stack_b) == 5 && second_content(stack_b) == 4)
_edge_flow_5(stack_a, stack_b);
else
_normal_flow_5(stack_a, stack_b);
}

void micro_sort(t_list **stack_a, t_list **stack_b, int num_a)
{
if (num_a == 4)
Expand Down

0 comments on commit 2a55ee2

Please sign in to comment.