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