ready to refactor
This commit is contained in:
parent
32979952b9
commit
fe48b78005
@ -24,6 +24,7 @@ typedef struct s_state
|
|||||||
int merge_to_a(t_state *state);
|
int merge_to_a(t_state *state);
|
||||||
void sortmore(t_state *state);
|
void sortmore(t_state *state);
|
||||||
|
|
||||||
|
void common_rotations(int *shortest_a, int *shortest_b, t_state *state);
|
||||||
void push_all_but_3_b(t_state *state);
|
void push_all_but_3_b(t_state *state);
|
||||||
int ft_abs(int a);
|
int ft_abs(int a);
|
||||||
int ft_max(int a, int b);
|
int ft_max(int a, int b);
|
||||||
|
|||||||
@ -15,10 +15,10 @@
|
|||||||
|
|
||||||
// abc
|
// abc
|
||||||
// acb rra sa
|
// acb rra sa
|
||||||
// bca rra
|
// bca (rra)
|
||||||
// bac sa
|
// bac sa
|
||||||
// cab ra
|
// cab (ra)
|
||||||
// cba sa rra
|
// cba sa (rra)
|
||||||
|
|
||||||
int sort3(t_state *state)
|
int sort3(t_state *state)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,6 +19,7 @@ int rotate_a_to_top(t_state *state)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//sort5
|
||||||
int merge_to_a(t_state *state)
|
int merge_to_a(t_state *state)
|
||||||
{
|
{
|
||||||
const int b = *(int *) state->b->content;
|
const int b = *(int *) state->b->content;
|
||||||
|
|||||||
@ -58,15 +58,23 @@ void b_merge_a(int idx_b, t_state *state)
|
|||||||
|
|
||||||
shortest_a = shortest_rotate(idx_a, ft_lstsize(state->a));
|
shortest_a = shortest_rotate(idx_a, ft_lstsize(state->a));
|
||||||
shortest_b = shortest_rotate(idx_b, ft_lstsize(state->b));
|
shortest_b = shortest_rotate(idx_b, ft_lstsize(state->b));
|
||||||
if (shortest_a * shortest_b > 0)
|
common_rotations(&shortest_a, &shortest_b, state);
|
||||||
|
rotate_a(shortest_a, state);
|
||||||
|
rotate_b(shortest_b, state);
|
||||||
|
pa(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void common_rotations(int *shortest_a, int *shortest_b, t_state *state)
|
||||||
{
|
{
|
||||||
if (shortest_a > 0)
|
if (*shortest_a * *shortest_b > 0)
|
||||||
{
|
{
|
||||||
while (shortest_a > 0 && shortest_b > 0)
|
if (*shortest_a > 0)
|
||||||
|
{
|
||||||
|
while (*shortest_a > 0 && *shortest_b > 0)
|
||||||
{
|
{
|
||||||
rr(state);
|
rr(state);
|
||||||
shortest_a--;
|
(*shortest_a)--;
|
||||||
shortest_b--;
|
(*shortest_b)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -74,14 +82,11 @@ void b_merge_a(int idx_b, t_state *state)
|
|||||||
while (shortest_a < 0 && shortest_b < 0)
|
while (shortest_a < 0 && shortest_b < 0)
|
||||||
{
|
{
|
||||||
rrr(state);
|
rrr(state);
|
||||||
shortest_a++;
|
(*shortest_a)++;
|
||||||
shortest_b++;
|
(*shortest_b)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rotate_a(shortest_a, state);
|
|
||||||
rotate_b(shortest_b, state);
|
|
||||||
pa(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sortmore(t_state *state)
|
void sortmore(t_state *state)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user