tgrekov-push_swap
HIVE push_swap July 2024
Loading...
Searching...
No Matches
r_rot.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* r_rot.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/06 06:33:08 by tgrekov #+# #+# */
9/* Updated: 2024/07/16 08:15:31 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <ft_printf.h>
21#include "../stack.h"
22
29static int _r_rot(t_stack stack)
30{
31 int temp;
32 int i;
33
34 if (stack.len < 2)
35 return (1);
36 temp = stack.n[stack.len - 1];
37 i = stack.len;
38 while (i-- > 1)
39 stack.n[i] = stack.n[i - 1];
40 stack.n[0] = temp;
41 return (0);
42}
43
51void r_rot(t_stack *stack, int mode)
52{
53 if (mode < 2 && !_r_rot(stack[mode]))
54 ft_printf("rr%c\n", 'a' + mode);
55 if (mode == 2)
56 {
57 _r_rot(stack[0]);
58 _r_rot(stack[1]);
59 ft_printf("rrr\n");
60 }
61}
int ft_printf(const char *format,...)
Prints and formats a variable set of arguments.
Definition ft_printf.c:252
void r_rot(t_stack *stack, int mode)
Shift all elements in stack 1, 2, or both up, depending on whether mode is set to 0,...
Definition r_rot.c:51
static int _r_rot(t_stack stack)
Shift all elements in stack up.
Definition r_rot.c:29