/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* operations.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/07 18:36:09 by erey-bet #+# #+# */ /* Updated: 2022/12/07 18:36:10 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "push_swap.h" void swap(t_stack *s, char *message) { long c; c = (*s).list[0]; (*s).list[0] = (*s).list[1]; (*s).list[1] = c; write(1, "s", 1); write(1, message, 1); write(1, "\n", 1); } void push(t_stack *s_push, t_stack *s_receive, char *message) { int i; long push; i = 0; push = (*s_push).list[0]; while (++i < (*s_push).len) (*s_push).list[i - 1] = (*s_push).list[i]; i = (*s_receive).len; while (i-- > 0) (*s_receive).list[i + 1] = (*s_receive).list[i]; (*s_receive).list[0] = push; (*s_receive).len += 1; (*s_push).len -= 1; write(1, "p", 1); write(1, message, 1); write(1, "\n", 1); } void rotate(t_stack *s, char *message) { int i; long rotate; i = 0; rotate = (*s).list[0]; while (++i < (*s).len) (*s).list[i - 1] = (*s).list[i]; (*s).list[(*s).len - 1] = rotate; write(1, "r", 1); write(1, message, 1); write(1, "\n", 1); } void rrotate(t_stack *s, char *message) { int i; long rotate; i = (*s).len - 1; rotate = (*s).list[(*s).len - 1]; while (--i > -1) (*s).list[i + 1] = (*s).list[i]; (*s).list[0] = rotate; write(1, "rr", 2); write(1, message, 1); write(1, "\n", 1); }