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