bubble algorithm WIP

This commit is contained in:
Maoake Teriierooiterai
2025-12-09 12:43:28 +01:00
parent c9066f4a9b
commit ad4275c206
3 changed files with 39 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bubble.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/09 11:56:23 by mteriier #+# #+# */
/* Updated: 2025/12/09 12:43:09 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void bubble_alg(t_stacks *stacks)
{
while (!check_order(stacks->a))
{
if (stacks->a->value > stacks->a->next->value)
sa(stacks);
ra(stacks);
}
}

10
main.c
View File

@@ -6,7 +6,7 @@
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 18:32:35 by mteriier #+# #+# */
/* Updated: 2025/12/09 11:39:55 by mteriier ### ########lyon.fr */
/* Updated: 2025/12/09 12:39:19 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -41,7 +41,7 @@ int main(int argc, char **argv)
if (argc > 1)
{
stacks = init_big_stacks(argc, argv);
print_all_stack(stacks->a, stacks->a, 'A');
/* 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');
@@ -65,6 +65,12 @@ int main(int argc, char **argv)
rrr(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
*/
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
bubble_alg(stacks);
print_all_stack(stacks->a, stacks->a, 'A');
print_all_stack(stacks->b, stacks->b, 'B');
}
stack_clear_all(stacks->a, stacks->a);
}

View File

@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 14:18:06 by dgaillet #+# #+# */
/* Updated: 2025/12/09 10:17:27 by mteriier ### ########lyon.fr */
/* Updated: 2025/12/09 12:41:07 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -38,6 +38,7 @@ void rr(t_stacks *stacks);
void sa(t_stacks *stacks);
void sb(t_stacks *stacks);
void ss(t_stacks *stacks);
/*FUNCTION UTILS*/
t_stack *new_stack(int value);
void stack_add_back(t_stack **stack, t_stack *new);
@@ -47,4 +48,10 @@ t_stack *parsing(int argc, char **argv);
t_stacks *init_big_stacks(int argc, char **argv);
int ft_atoi(const char *nptr);
/*ALGORITHM UTILS*/
int check_order(t_stack *stack);
/*ALGORITHMS*/
void bubble_alg(t_stacks *stacks);
#endif