diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-18 12:11:36 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-18 12:11:36 +0100 |
| commit | 5e0e41652315114a8b0d883c473dbbbfc1c28342 (patch) | |
| tree | 8e1440ccf9d686294c05c6f8b5907fe90ba4fda8 /src/common | |
| parent | 2d34349b54a9fed4d34c96bdbec5172f7695cf60 (diff) | |
| download | push_swap-5e0e41652315114a8b0d883c473dbbbfc1c28342.tar.gz push_swap-5e0e41652315114a8b0d883c473dbbbfc1c28342.tar.bz2 push_swap-5e0e41652315114a8b0d883c473dbbbfc1c28342.zip | |
filled action functions (propably bloat), checker working, stack functions not so much
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/action.c | 34 | ||||
| -rw-r--r-- | src/common/common.h | 13 | ||||
| -rw-r--r-- | src/common/stack.c | 1 |
3 files changed, 39 insertions, 9 deletions
diff --git a/src/common/action.c b/src/common/action.c index bfbe436..c095e59 100644 --- a/src/common/action.c +++ b/src/common/action.c @@ -2,55 +2,71 @@ void swap_a(t_stack *a) { - + stack_swap(a); } void swap_b(t_stack *b) { - + stack_swap(b); } void swap_both(t_stack *a, t_stack *b) { - + swap_a(a); + swap_b(b); } void push_a(t_stack *a, t_stack *b) { + int tmp; + if (stack_empty(b)) + return ; + tmp = stack_peek(b); + stack_pop(b); + stack_push(a, tmp); } void push_b(t_stack *b, t_stack *a) { + int tmp; + + if (stack_empty(a)) + return ; + tmp = stack_peek(a); + stack_pop(a); + stack_push(b, tmp); } void rotate_a(t_stack *a) { - + stack_rotate(a); } void rotate_b(t_stack *b) { - + stack_rotate(b); } void rotate_both(t_stack *a, t_stack *b) { - + rotate_a(a); + rotate_b(b); } void reverse_rotate_a(t_stack *a) { - + stack_reverse_rotate(a); } void reverse_rotate_b(t_stack *b) { - + stack_reverse_rotate(b); } void reverse_rotate_both(t_stack *a, t_stack *b) { - + reverse_rotate_a(a); + reverse_rotate_b(b); } diff --git a/src/common/common.h b/src/common/common.h index 18ccae3..b914d5e 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -1,3 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* common.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/18 11:20:54 by cacharle #+# #+# */ +/* Updated: 2020/01/18 11:21:03 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include <stdio.h> + #ifndef STACK_H # define STACK_H diff --git a/src/common/stack.c b/src/common/stack.c index 02d3207..269dbc4 100644 --- a/src/common/stack.c +++ b/src/common/stack.c @@ -26,6 +26,7 @@ void stack_destroy(t_stack *stack) void stack_push(t_stack *stack, int n) { stack->top++; + printf("%d\n", stack->top); stack->elements[stack->top] = n; } |
