mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Algorithm firsts utils (stack size + check order)
This commit is contained in:
27
algorithms/utils/check_order.c
Normal file
27
algorithms/utils/check_order.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* check_order.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 11:57:06 by mteriier #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 12:02:28 by mteriier ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int check_order(t_stack *stack)
|
||||||
|
{
|
||||||
|
t_stack *first;
|
||||||
|
|
||||||
|
first = stack;
|
||||||
|
while (stack->next != first)
|
||||||
|
{
|
||||||
|
if (stack->value > stack->next->value)
|
||||||
|
return (0);
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
30
algorithms/utils/stack_len.c
Normal file
30
algorithms/utils/stack_len.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* stack_len.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/12/09 12:05:15 by mteriier #+# #+# */
|
||||||
|
/* Updated: 2025/12/09 12:07:29 by mteriier ### ########lyon.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int stack_len(t_stack *stack)
|
||||||
|
{
|
||||||
|
t_stack *first;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
first = stack;
|
||||||
|
if (!stack)
|
||||||
|
return (0);
|
||||||
|
i = 1;
|
||||||
|
while (stack->next != first)
|
||||||
|
{
|
||||||
|
stack = stack->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user