mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
bubble algorithm WIP
This commit is contained in:
23
algorithms/bubble/bubble.c
Normal file
23
algorithms/bubble/bubble.c
Normal 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
10
main.c
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user