42 lines
1.4 KiB
C
42 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* sort3.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2024/11/07 12:09:48 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2024/11/07 13:33:18 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include "push_swap.h"
|
|
|
|
// abc
|
|
// acb rra sa
|
|
// bca (rra)
|
|
// bac sa
|
|
// cab (ra)
|
|
// cba sa (rra)
|
|
|
|
int sort3(t_state *state)
|
|
{
|
|
const int a = *((int *) state->a->content);
|
|
const int b = *((int *) state->a->next->content);
|
|
const int c = *((int *) state->a->next->next->content);
|
|
|
|
if (ft_lstsize(state->a) != 3)
|
|
return (0);
|
|
if (a < b && b < c)
|
|
return (1);
|
|
else if (a < b && b > c && a < c)
|
|
{
|
|
rra(state);
|
|
sa(state);
|
|
}
|
|
else if ((a > b && a < c) || (a > b && b > c))
|
|
sa(state);
|
|
return (1);
|
|
}
|