diff --git a/algorithms/bubble/bubble.c b/algorithms/bubble/bubble.c new file mode 100644 index 0000000..b396341 --- /dev/null +++ b/algorithms/bubble/bubble.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bubble.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mteriier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); + } +} diff --git a/main.c b/main.c index c5cf6e9..1327daa 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: mteriier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/push_swap.h b/push_swap.h index 6f0b3f4..b96637a 100644 --- a/push_swap.h +++ b/push_swap.h @@ -6,7 +6,7 @@ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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