push swap specific func wip
This commit is contained in:
parent
87443af3c8
commit
ba33cb63c8
39
include/push_swap.h
Normal file
39
include/push_swap.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* By: ablanken <ablanken at student dot 42barcelona dot com */
|
||||
/* */
|
||||
/* Created: foo bar by ablanken */
|
||||
/* Updated: foo bar by Andrea Blanke */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUSH_SWAP_H
|
||||
# define PUSH_SWAP_H
|
||||
|
||||
# include <ft_stack.h>
|
||||
|
||||
typedef struct s_push_swap_ctx
|
||||
{
|
||||
unsigned int instruction_counter;
|
||||
t_stack *stack_a;
|
||||
t_stack *stack_b;
|
||||
} t_push_swap_ctx;
|
||||
|
||||
void push_swap_pa(t_push_swap_ctx *ctx);
|
||||
void push_swap_pb(t_push_swap_ctx *ctx);
|
||||
void push_swap_ra(t_push_swap_ctx *ctx);
|
||||
void push_swap_rb(t_push_swap_ctx *ctx);
|
||||
void push_swap_rr(t_push_swap_ctx *ctx);
|
||||
void push_swap_rra(t_push_swap_ctx *ctx);
|
||||
void push_swap_rrb(t_push_swap_ctx *ctx);
|
||||
void push_swap_rrr(t_push_swap_ctx *ctx);
|
||||
void push_swap_sa(t_push_swap_ctx *ctx);
|
||||
void push_swap_sb(t_push_swap_ctx *ctx);
|
||||
void push_swap_ss(t_push_swap_ctx *ctx);
|
||||
|
||||
#endif
|
||||
|
||||
// vi: noet sw=4 ts=4:
|
48
src/push_swap.c
Normal file
48
src/push_swap.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* By: ablanken <ablanken at student dot 42barcelona dot com */
|
||||
/* */
|
||||
/* Created: foo bar by ablanken */
|
||||
/* Updated: foo bar by Andrea Blanke */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <push_swap.h>
|
||||
|
||||
#include "ft_stack.h"
|
||||
|
||||
void push_swap_pa(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_push(ctx->stack_a, stack_pop(ctx->stack_b));
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_pb(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_push(ctx->stack_b, stack_pop(ctx->stack_a));
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_sa(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_swap(ctx->stack_a);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_sb(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_swap(ctx->stack_b);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_ss(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_swap(ctx->stack_a);
|
||||
stack_swap(ctx->stack_b);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
// vi: noet sw=4 ts=4:
|
36
src/reverse_rotate.c
Normal file
36
src/reverse_rotate.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* By: ablanken <ablanken at student dot 42barcelona dot com */
|
||||
/* */
|
||||
/* Created: foo bar by ablanken */
|
||||
/* Updated: foo bar by Andrea Blanke */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <push_swap.h>
|
||||
|
||||
#include "ft_stack.h"
|
||||
|
||||
void push_swap_rra(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_rrotate(ctx->stack_a, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_rrb(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_rrotate(ctx->stack_b, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_rrr(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_rrotate(ctx->stack_a, 1);
|
||||
stack_rrotate(ctx->stack_b, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
// vi: noet sw=4 ts=4:
|
36
src/rotate.c
Normal file
36
src/rotate.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* By: ablanken <ablanken at student dot 42barcelona dot com */
|
||||
/* */
|
||||
/* Created: foo bar by ablanken */
|
||||
/* Updated: foo bar by Andrea Blanke */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <push_swap.h>
|
||||
|
||||
#include "ft_stack.h"
|
||||
|
||||
void push_swap_ra(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_lrotate(ctx->stack_a, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_rb(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_lrotate(ctx->stack_b, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
void push_swap_rr(t_push_swap_ctx *ctx)
|
||||
{
|
||||
stack_lrotate(ctx->stack_a, 1);
|
||||
stack_lrotate(ctx->stack_b, 1);
|
||||
ctx->instruction_counter++;
|
||||
}
|
||||
|
||||
// vi: noet sw=4 ts=4:
|
Loading…
Reference in a new issue