Add bench mode and algo in t_stacks

This commit is contained in:
2026-01-08 13:54:29 +00:00
parent 765ec373e5
commit 2ba9029955
6 changed files with 84 additions and 21 deletions

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */ /* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */ /* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
/* Updated: 2026/01/07 10:30:42 by dgaillet ### ########lyon.fr */ /* Updated: 2026/01/08 13:36:33 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -24,6 +24,18 @@ typedef struct s_stacks
{ {
t_stack *a; t_stack *a;
t_stack *b; t_stack *b;
int algo;
int bench;
unsigned int ra;
unsigned int rb;
unsigned int rr;
unsigned int rra;
unsigned int rrb;
unsigned int rrr;
unsigned int pa;
unsigned int pb;
unsigned int sa;
unsigned int sb;
} t_stacks; } t_stacks;
/* PRINT STACK FUNCTION*/ /* PRINT STACK FUNCTION*/

View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */ /* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 16:21:05 by mteriier #+# #+# */ /* Created: 2025/12/08 16:21:05 by mteriier #+# #+# */
/* Updated: 2025/12/09 10:19:17 by mteriier ### ########lyon.fr */ /* Updated: 2026/01/08 13:54:18 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -62,16 +62,34 @@ static t_stack *special_parsing(int argc, char **argv, int mod)
while () while ()
} }
static void set_t_stacks(t_stacks *stacks)
{
stacks->a = NULL;
stacks->b = NULL;
stacks->algo = 0;
stacks->bench = 0;
stacks->sa = 0;
stacks->sb = 0;
stacks->ss = 0;
stacks->pa = 0;
stacks->pb = 0;
stacks->ra = 0;
stacks->rb = 0;
stacks->rr = 0;
stacks->rra = 0;
stacks->rrb = 0;
stacks->rrr = 0;
}
t_stacks *init_piles(int argc, char **argv, int mod) t_stacks *init_piles(int argc, char **argv, int mod)
{ {
t_stacks *stacks; t_stacks *stacks;
t_stack *a; t_stack *a;
stacks = malloc(sizeof(t_stacks)); stacks = malloc(sizeof(t_stacks));
stacks->a = NULL;
stacks->b = NULL;
if (!stacks) if (!stacks)
return (NULL); return (NULL);
set_t_stacks(stacks);
a = parsing(argc, argv, mod); a = parsing(argc, argv, mod);
stacks->a = a; stacks->a = a;
return (stacks); return (stacks);

View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */ /* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */ /* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */
/* Updated: 2025/12/12 11:39:33 by dgaillet ### ########lyon.fr */ /* Updated: 2026/01/08 13:52:01 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -30,6 +30,9 @@ void pa(t_stacks *stacks)
stacks->b = stacks->b->next; stacks->b = stacks->b->next;
} }
stack_add_front(&(stacks->a), b_push); stack_add_front(&(stacks->a), b_push);
if (stacks->bench)
stacks->pa++;
else
write(1, "pa\n", 3); write(1, "pa\n", 3);
} }
@@ -49,5 +52,8 @@ void pb(t_stacks *stacks)
stacks->a = stacks->a->next; stacks->a = stacks->a->next;
} }
stack_add_front(&(stacks->b), a_push); stack_add_front(&(stacks->b), a_push);
if (stacks->bench)
stacks->pb++;
else
write(1, "pb\n", 3); write(1, "pb\n", 3);
} }

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */ /* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:43:45 by dgaillet #+# #+# */ /* Created: 2025/12/08 14:43:45 by dgaillet #+# #+# */
/* Updated: 2025/12/12 11:39:25 by dgaillet ### ########lyon.fr */ /* Updated: 2026/01/08 13:52:33 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -17,6 +17,9 @@ void rra(t_stacks *stacks)
{ {
if (stacks && stacks->a && stacks->a->previous) if (stacks && stacks->a && stacks->a->previous)
stacks->a = stacks->a->previous; stacks->a = stacks->a->previous;
if (stacks->bench)
stacks->rra++;
else
write(1, "rra\n", 4); write(1, "rra\n", 4);
} }
@@ -24,6 +27,9 @@ void rrb(t_stacks *stacks)
{ {
if (stacks && stacks->b && stacks->b->previous) if (stacks && stacks->b && stacks->b->previous)
stacks->b = stacks->b->previous; stacks->b = stacks->b->previous;
if (stacks->bench)
stacks->rrb++;
else
write(1, "rrb\n", 4); write(1, "rrb\n", 4);
} }
@@ -33,5 +39,8 @@ void rrr(t_stacks *stacks)
stacks->b = stacks->b->previous; stacks->b = stacks->b->previous;
if (stacks && stacks->a && stacks->a->previous) if (stacks && stacks->a && stacks->a->previous)
stacks->a = stacks->a->previous; stacks->a = stacks->a->previous;
if (stacks->bench)
stacks->rrr++;
else
write(1, "rrr\n", 4); write(1, "rrr\n", 4);
} }

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */ /* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:32:10 by dgaillet #+# #+# */ /* Created: 2025/12/08 14:32:10 by dgaillet #+# #+# */
/* Updated: 2025/12/12 11:39:17 by dgaillet ### ########lyon.fr */ /* Updated: 2026/01/08 13:52:59 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -17,6 +17,9 @@ void ra(t_stacks *stacks)
{ {
if (stacks && stacks->a && stacks->a->next) if (stacks && stacks->a && stacks->a->next)
stacks->a = stacks->a->next; stacks->a = stacks->a->next;
if (stacks->bench)
stacks->ra++;
else
write(1, "ra\n", 3); write(1, "ra\n", 3);
} }
@@ -24,6 +27,9 @@ void rb(t_stacks *stacks)
{ {
if (stacks && stacks->b && stacks->b->next) if (stacks && stacks->b && stacks->b->next)
stacks->b = stacks->b->next; stacks->b = stacks->b->next;
if (stacks->bench)
stacks->rb++;
else
write(1, "rb\n", 3); write(1, "rb\n", 3);
} }
@@ -33,5 +39,8 @@ void rr(t_stacks *stacks)
stacks->a = stacks->a->next; stacks->a = stacks->a->next;
if (stacks && stacks->b && stacks->b->next) if (stacks && stacks->b && stacks->b->next)
stacks->b = stacks->b->next; stacks->b = stacks->b->next;
if (stacks->bench)
stacks->rr++;
else
write(1, "rr\n", 3); write(1, "rr\n", 3);
} }

View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */ /* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:48:44 by mteriier #+# #+# */ /* Created: 2025/12/08 14:48:44 by mteriier #+# #+# */
/* Updated: 2025/12/12 11:38:52 by dgaillet ### ########lyon.fr */ /* Updated: 2026/01/08 13:53:40 by dgaillet ### ########lyon.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -24,6 +24,9 @@ void sa(t_stacks *stacks)
stock = a->value; stock = a->value;
a->value = a->next->value; a->value = a->next->value;
a->next->value = stock; a->next->value = stock;
if (stacks->bench)
stacks->sa++;
else
write(1, "sa\n", 3); write(1, "sa\n", 3);
} }
@@ -38,6 +41,9 @@ void sb(t_stacks *stacks)
stock = b->value; stock = b->value;
b->value = b->next->value; b->value = b->next->value;
b->next->value = stock; b->next->value = stock;
if (stacks->bench)
stacks->sb++;
else
write(1, "sb\n", 3); write(1, "sb\n", 3);
} }
@@ -63,5 +69,8 @@ void ss(t_stacks *stacks)
a->value = a->next->value; a->value = a->next->value;
a->next->value = stock; a->next->value = stock;
} }
if (stacks->bench)
stacks->ss++;
else
write(1, "ss\n", 3); write(1, "ss\n", 3);
} }