all basics functions has been tested we can start the sort algorithms

This commit is contained in:
Maoake Teriierooiterai
2025-12-09 11:42:37 +01:00
parent 30b306d2c2
commit 67d7509faf
9 changed files with 99 additions and 38 deletions

BIN
.main.c.swp Normal file

Binary file not shown.

BIN
.parsing.c.swp Normal file

Binary file not shown.

44
main.c
View File

@@ -6,35 +6,65 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 18:32:35 by mteriier #+# #+# */
/* Updated: 2025/12/08 20:36:49 by mteriier ### ########.fr */
/* Updated: 2025/12/09 11:39:55 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdio.h>
#include <stdlib.h>
void print_all_stack(t_stack *stack, t_stack *first)
void print_all_stack(t_stack *stack, t_stack *first, char pile)
{
t_stack *tmp;
int i;
tmp = stack;
printf("TAB\n");
i = 0;
printf("TAB %c : \n", pile);
if (!stack || !first)
return ;
while (tmp->next != first)
{
printf("[%d] ", tmp->value);
tmp = tmp->next;
i++;
}
printf("[%d] \n", tmp->value);
}
int main(int argc, char **argv)
{
t_stack *first;
t_stacks *stacks;
stacks = NULL;
if (argc > 1)
{
first = parsing(argc, argv);
print_all_stack(first, first);
stacks = init_big_stacks(argc, argv);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
sa(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
pb(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
pa(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
rra(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
pb(stacks);
pb(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
rrb(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
rrr(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
}
stack_clear_all(first, first);
stack_clear_all(stacks->a, stacks->a);
}

View File

@@ -6,17 +6,16 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 16:21:05 by mteriier #+# #+# */
/* Updated: 2025/12/08 20:31:37 by mteriier ### ########.fr */
/* Updated: 2025/12/09 10:19:17 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdlib.h>
#include <stdio.h>
t_stack *parsing(int argc, char **argv)
{
size_t i;
int i;
int stock;
t_stack *first;
t_stack *new;
@@ -39,3 +38,16 @@ t_stack *parsing(int argc, char **argv)
}
return (first);
}
t_stacks *init_big_stacks(int argc, char **argv)
{
t_stacks *stacks;
t_stack *a;
stacks = malloc(sizeof(t_stacks));
if (!stacks)
return (NULL);
a = parsing(argc, argv);
stacks->a = a;
return (stacks);
}

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
/* Updated: 2025/12/08 20:28:41 by mteriier ### ########.fr */
/* Updated: 2025/12/09 10:17:27 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -44,6 +44,7 @@ void stack_add_back(t_stack **stack, t_stack *new);
void stack_add_front(t_stack **stack, t_stack *new);
void stack_clear_all(t_stack *stack, t_stack *first);
t_stack *parsing(int argc, char **argv);
t_stacks *init_big_stacks(int argc, char **argv);
int ft_atoi(const char *nptr);
#endif

BIN
stack_utils/.push.c.swp Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -6,28 +6,48 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 15:09:40 by mteriier #+# #+# */
/* Updated: 2025/12/08 19:37:01 by mteriier ### ########.fr */
/* Updated: 2025/12/09 11:36:36 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../push_swap.h"
#include <stdlib.h>
void pa(t_stacks *stacks)
{
t_stack *a;
t_stack *b_push;
if (!stacks || !stacks->b)
return ;
a = stacks->a;
a->value = stacks->b->value;
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);
}
#include <stdio.h>
void pb(t_stacks *stacks)
{
t_stack *b;
t_stack *a_push;
if (!stacks || !stacks->a)
return ;
b = stacks->b;
b->value = stacks->a->value;
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);
}

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */
/* Updated: 2025/12/08 20:33:58 by mteriier ### ########.fr */
/* Updated: 2025/12/09 08:51:33 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -26,8 +26,6 @@ t_stack *new_stack(int value)
return (new);
}
#include <stdio.h>
void stack_add_back(t_stack **stack, t_stack *new)
{
if (!stack || !new)