made some utilities
This commit is contained in:
parent
9b812a3479
commit
2c9fdc3f48
64
src/util/utils.c
Normal file
64
src/util/utils.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* utils.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2024/11/10 14:44:51 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2024/11/10 16:34:08 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int shortest_rotate(int index, int size)
|
||||||
|
{
|
||||||
|
if (index <= size / 2)
|
||||||
|
return (index);
|
||||||
|
return (-1 * (size - index));
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotate_to(int index, t_state state, char c)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
if (c == 'a')
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int index_of(int number, t_list *stack)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (stack)
|
||||||
|
{
|
||||||
|
if (*(int *) stack->content == number)
|
||||||
|
return (i);
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int put_at_index(int number, t_list *stack)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (number < stack_min(stack) || number > stack_max(stack))
|
||||||
|
i = index_of(stack_min(stack), stack);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (number > *(int *) ft_lstat(stack, i)->content
|
||||||
|
&& number > *(int *) ft_lstat(stack, i)->content
|
||||||
|
&& i < ft_lstsize(stack))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == ft_lstsize(stack))
|
||||||
|
return (0);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user