mirror of
https://github.com/Ladebeze66/pushswap.git
synced 2025-12-15 13:46:55 +01:00
43 lines
1.4 KiB
C
Executable File
43 lines
1.4 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* sort_tiny.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/07/31 18:00:36 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/07/31 18:06:35 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
static int find_highest_index(t_stack *stack)
|
|
{
|
|
int index;
|
|
|
|
index = stack->index;
|
|
while (stack)
|
|
{
|
|
if (stack->index > index)
|
|
index = stack->index;
|
|
stack = stack->next;
|
|
}
|
|
return (index);
|
|
}
|
|
|
|
void tiny_sort(t_stack **stack)
|
|
{
|
|
int highest;
|
|
|
|
if (is_sorted(*stack))
|
|
return ;
|
|
highest = find_highest_index(*stack);
|
|
if ((*stack)->index == highest)
|
|
do_ra(stack);
|
|
else if ((*stack)->next->index == highest)
|
|
do_rra(stack);
|
|
if ((*stack)->index > (*stack)->next->index)
|
|
do_sa(stack);
|
|
}
|