mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
starting the bonus and modify the name folder headers -> includes
This commit is contained in:
2
Makefile
2
Makefile
@@ -20,7 +20,7 @@ FLAGS_DIR = flags
|
||||
|
||||
CHECKER_DIR = checker
|
||||
|
||||
INCLUDES = headers
|
||||
INCLUDES = includes
|
||||
|
||||
#============================
|
||||
# ALL FILES WITHOUT PATH
|
||||
|
||||
0
bonus/Makefile
Normal file
0
bonus/Makefile
Normal file
0
bonus/check/check_error.c
Normal file
0
bonus/check/check_error.c
Normal file
0
bonus/end_check/end_check.c
Normal file
0
bonus/end_check/end_check.c
Normal file
0
bonus/main.c
Normal file
0
bonus/main.c
Normal file
0
bonus/parsing/parsing.c
Normal file
0
bonus/parsing/parsing.c
Normal file
51
bonus/utils/push.c
Normal file
51
bonus/utils/push.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* push.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/08 13:57:56 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void pa(t_stacks *stacks)
|
||||
{
|
||||
t_stack *b_push;
|
||||
|
||||
if (!stacks || !stacks->b)
|
||||
return ;
|
||||
b_push = stacks->b;
|
||||
if (stacks->b->next == stacks->b)
|
||||
stacks->b = NULL;
|
||||
else
|
||||
{
|
||||
stacks->b->next->previous = stacks->b->previous;
|
||||
stacks->b->previous->next = stacks->b->next;
|
||||
stacks->b = stacks->b->next;
|
||||
}
|
||||
stack_add_front(&(stacks->a), b_push);
|
||||
}
|
||||
|
||||
void pb(t_stacks *stacks)
|
||||
{
|
||||
t_stack *a_push;
|
||||
|
||||
if (!stacks || !stacks->a)
|
||||
return ;
|
||||
a_push = stacks->a;
|
||||
if (stacks->a->next == stacks->a)
|
||||
stacks->a = NULL;
|
||||
else
|
||||
{
|
||||
stacks->a->next->previous = stacks->a->previous;
|
||||
stacks->a->previous->next = stacks->a->next;
|
||||
stacks->a = stacks->a->next;
|
||||
}
|
||||
stack_add_front(&(stacks->b), a_push);
|
||||
}
|
||||
34
bonus/utils/rev_rotate.c
Normal file
34
bonus/utils/rev_rotate.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rev_rotate.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 14:43:45 by dgaillet #+# #+# */
|
||||
/* Updated: 2026/01/08 13:57:27 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void rra(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->a && stacks->a->previous)
|
||||
stacks->a = stacks->a->previous;
|
||||
}
|
||||
|
||||
void rrb(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->b && stacks->b->previous)
|
||||
stacks->b = stacks->b->previous;
|
||||
}
|
||||
|
||||
void rrr(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->b && stacks->b->previous)
|
||||
stacks->b = stacks->b->previous;
|
||||
if (stacks && stacks->a && stacks->a->previous)
|
||||
stacks->a = stacks->a->previous;
|
||||
}
|
||||
34
bonus/utils/rotate.c
Normal file
34
bonus/utils/rotate.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rotate.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 14:32:10 by dgaillet #+# #+# */
|
||||
/* Updated: 2026/01/08 13:57:47 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void ra(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->a && stacks->a->next)
|
||||
stacks->a = stacks->a->next;
|
||||
}
|
||||
|
||||
void rb(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->b && stacks->b->next)
|
||||
stacks->b = stacks->b->next;
|
||||
}
|
||||
|
||||
void rr(t_stacks *stacks)
|
||||
{
|
||||
if (stacks && stacks->a && stacks->a->next)
|
||||
stacks->a = stacks->a->next;
|
||||
if (stacks && stacks->b && stacks->b->next)
|
||||
stacks->b = stacks->b->next;
|
||||
}
|
||||
54
bonus/utils/stack_add.c
Normal file
54
bonus/utils/stack_add.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_add.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/12 11:39:09 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_stack *new_stack(int value)
|
||||
{
|
||||
t_stack *new;
|
||||
|
||||
new = malloc(sizeof(t_stack));
|
||||
if (!new)
|
||||
return (NULL);
|
||||
new->value = value;
|
||||
new->next = NULL;
|
||||
new->previous = NULL;
|
||||
return (new);
|
||||
}
|
||||
|
||||
void stack_add_back(t_stack **stack, t_stack *new)
|
||||
{
|
||||
if (!stack || !new)
|
||||
return ;
|
||||
if (*stack == NULL)
|
||||
{
|
||||
(*stack) = new;
|
||||
new->next = new;
|
||||
new->previous = new;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*stack)->previous->next = new;
|
||||
new->previous = (*stack)->previous;
|
||||
(*stack)->previous = new;
|
||||
new->next = *stack;
|
||||
}
|
||||
}
|
||||
|
||||
void stack_add_front(t_stack **stack, t_stack *new)
|
||||
{
|
||||
if (!stack || !new)
|
||||
return ;
|
||||
stack_add_back(stack, new);
|
||||
*stack = new;
|
||||
}
|
||||
32
bonus/utils/stack_remove.c
Normal file
32
bonus/utils/stack_remove.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_remove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 16:05:27 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/12 11:39:02 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void stack_clear_all(t_stack *stack, t_stack *first)
|
||||
{
|
||||
if (!stack)
|
||||
return ;
|
||||
if (stack->next != first)
|
||||
stack_clear_all(stack->next, first);
|
||||
free(stack);
|
||||
}
|
||||
|
||||
void free_all(t_stacks *stacks)
|
||||
{
|
||||
if (stacks->a)
|
||||
stack_clear_all(stacks->a, stacks->a);
|
||||
if (stacks->b)
|
||||
stack_clear_all(stacks->b, stacks->b);
|
||||
free(stacks);
|
||||
}
|
||||
63
bonus/utils/stacks_len.c
Normal file
63
bonus/utils/stacks_len.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stacks_len.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/09 13:11:50 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/09 13:19:21 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
int stack_a_len(t_stacks *stacks)
|
||||
{
|
||||
t_stack *first;
|
||||
t_stack *a_stack;
|
||||
int len;
|
||||
|
||||
a_stack = stacks->a;
|
||||
first = a_stack;
|
||||
if (!a_stack)
|
||||
return (0);
|
||||
len = 1;
|
||||
while (a_stack->next != first)
|
||||
{
|
||||
a_stack = a_stack->next;
|
||||
len++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
int stack_b_len(t_stacks *stacks)
|
||||
{
|
||||
t_stack *first;
|
||||
t_stack *b_stack;
|
||||
int len;
|
||||
|
||||
b_stack = stacks->b;
|
||||
first = b_stack;
|
||||
if (!b_stack)
|
||||
return (0);
|
||||
len = 1;
|
||||
while (b_stack->next != first)
|
||||
{
|
||||
b_stack = b_stack->next;
|
||||
len++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
int highest_stack_len(t_stacks *stacks)
|
||||
{
|
||||
int a_len;
|
||||
int b_len;
|
||||
|
||||
a_len = stack_a_len(stacks);
|
||||
b_len = stack_b_len(stacks);
|
||||
if (a_len > b_len)
|
||||
return (a_len);
|
||||
return (b_len);
|
||||
}
|
||||
64
bonus/utils/swap.c
Normal file
64
bonus/utils/swap.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 14:48:44 by mteriier #+# #+# */
|
||||
/* Updated: 2026/01/08 13:58:13 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void sa(t_stacks *stacks)
|
||||
{
|
||||
t_stack *a;
|
||||
int stock;
|
||||
|
||||
if (!stacks || !stacks->a || !stacks->a->next)
|
||||
return ;
|
||||
a = stacks->a;
|
||||
stock = a->value;
|
||||
a->value = a->next->value;
|
||||
a->next->value = stock;
|
||||
}
|
||||
|
||||
void sb(t_stacks *stacks)
|
||||
{
|
||||
t_stack *b;
|
||||
int stock;
|
||||
|
||||
if (!stacks || !stacks->b || !stacks->b->next)
|
||||
return ;
|
||||
b = stacks->b;
|
||||
stock = b->value;
|
||||
b->value = b->next->value;
|
||||
b->next->value = stock;
|
||||
}
|
||||
|
||||
void ss(t_stacks *stacks)
|
||||
{
|
||||
t_stack *b;
|
||||
t_stack *a;
|
||||
int stock;
|
||||
|
||||
if (!stacks)
|
||||
return ;
|
||||
if (stacks->b && stacks->b->next)
|
||||
{
|
||||
b = stacks->b;
|
||||
stock = b->value;
|
||||
b->value = b->next->value;
|
||||
b->next->value = stock;
|
||||
}
|
||||
if (stacks->a && stacks->a->next)
|
||||
{
|
||||
a = stacks->a;
|
||||
stock = a->value;
|
||||
a->value = a->next->value;
|
||||
a->next->value = stock;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user