Initial commit

This commit is contained in:
2026-01-09 15:20:33 +01:00
commit d0a9d550e5
31 changed files with 2248 additions and 0 deletions

61
srcs/push_swap/goto.c Normal file
View File

@@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* goto.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lejulien <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/01 17:34:57 by lejulien #+# #+# */
/* Updated: 2021/04/04 17:54:41 by lejulien ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "../utils/utils.h"
static void
ft_goto_rotate(t_stack **stack, int pos, char *name)
{
while (pos != 0)
{
rotate(stack);
ft_putstr("r");
ft_putstr(name);
ft_putstr("\n");
pos--;
}
}
static void
ft_goto_r_rotate(t_stack **stack, int pos, char *name)
{
while (pos != stack_len(stack))
{
r_rotate(stack);
ft_putstr("rr");
ft_putstr(name);
ft_putstr("\n");
pos++;
}
}
void
ft_goto(t_stack **stack, int val, char *name)
{
t_stack *ptr;
int pos;
pos = 0;
ptr = *stack;
while (ptr && ptr->value != val)
{
ptr = ptr->next;
pos++;
}
if (pos == 0)
return ;
if (pos <= (int)(stack_len(stack) / 2))
ft_goto_rotate(stack, pos, name);
else
ft_goto_r_rotate(stack, pos, name);
}