Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
58
sources/sort_small.c
Executable file
58
sources/sort_small.c
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* sort_small.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/13 12:07:14 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/06 11:55:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/push_swap.h"
|
||||
|
||||
static void sort_132(t_list **stack_a)
|
||||
{
|
||||
ra(stack_a);
|
||||
sa(stack_a);
|
||||
rra(stack_a);
|
||||
}
|
||||
|
||||
static void sort_231(t_list **stack_a, t_list *head, int min)
|
||||
{
|
||||
if (head->next->index == min)
|
||||
sa(stack_a);
|
||||
else
|
||||
rra(stack_a);
|
||||
}
|
||||
|
||||
static void sort_312(t_list **stack_a, t_list *head, int min)
|
||||
{
|
||||
if (head->next->index == min)
|
||||
ra(stack_a);
|
||||
else
|
||||
{
|
||||
sa(stack_a);
|
||||
rra(stack_a);
|
||||
}
|
||||
}
|
||||
|
||||
void sort_3(t_list **stack_a)
|
||||
{
|
||||
t_list *head;
|
||||
int min;
|
||||
int next_min;
|
||||
|
||||
head = *stack_a;
|
||||
min = get_min(stack_a, -1);
|
||||
next_min = get_min(stack_a, min);
|
||||
if (is_sorted(stack_a) == 1)
|
||||
return ;
|
||||
if (head->index == min && head->next->index != next_min)
|
||||
sort_132(stack_a);
|
||||
else if (head->index == next_min)
|
||||
sort_231(stack_a, head, min);
|
||||
else
|
||||
sort_312(stack_a, head, min);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue