tgrekov-push_swap
HIVE push_swap July 2024
Loading...
Searching...
No Matches
push.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* push.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/06 05:49:10 by tgrekov #+# #+# */
9/* Updated: 2024/07/17 08:34:57 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <ft_printf.h>
21#include "../stack.h"
22
30static int _push(t_stack *src, t_stack *dst)
31{
32 int i;
33
34 if (!src->len)
35 return (1);
36 dst->len++;
37 i = dst->len;
38 while (i-- > 1)
39 dst->n[i] = dst->n[i - 1];
40 dst->n[0] = src->n[0];
41 src->len--;
42 i = 0;
43 while (i++ < src->len)
44 src->n[i - 1] = src->n[i];
45 return (0);
46}
47
55void push(t_stack *stack, int mode)
56{
57 if (!_push(&stack[mode], &stack[1 - mode]))
58 ft_printf("p%c\n", 'b' - mode);
59}
int ft_printf(const char *format,...)
Prints and formats a variable set of arguments.
Definition ft_printf.c:252
void push(t_stack *stack, int mode)
Push the first element from stack 1 or 2 into the other stack, depending on whether mode is set to 0 ...
Definition push.c:55
static int _push(t_stack *src, t_stack *dst)
Push the first element out of src out and into dst.
Definition push.c:30