mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
bubble v1
This commit is contained in:
@@ -6,18 +6,38 @@
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/09 11:56:23 by mteriier #+# #+# */
|
||||
/* Updated: 2025/12/09 13:19:39 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/12/09 14:09:07 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include "unistd.h"
|
||||
|
||||
void bubble_alg(t_stacks *stacks)
|
||||
{
|
||||
while (!check_order(stacks->a))
|
||||
while (stack_a_len(stacks))
|
||||
{
|
||||
if (stacks->a->value > stacks->a->next->value)
|
||||
{
|
||||
sa(stacks);
|
||||
ra(stacks);
|
||||
write(1, "sa\n", 3);
|
||||
}
|
||||
pb(stacks);
|
||||
write(1, "pb\n", 3);
|
||||
// print_stacks(stacks, highest_stack_len(stacks), stacks->a, stacks->b);
|
||||
}
|
||||
while (stack_b_len(stacks))
|
||||
{
|
||||
if (stacks->b->value < stacks->b->next->value)
|
||||
{
|
||||
sb(stacks);
|
||||
write(1, "sa\n", 3);
|
||||
}
|
||||
pa(stacks);
|
||||
write(1, "pb\n", 3);
|
||||
// print_stacks(stacks, highest_stack_len(stacks), stacks->a, stacks->b);
|
||||
}
|
||||
if (check_order(stacks->a))
|
||||
return ;
|
||||
bubble_alg(stacks);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/09 11:57:06 by mteriier #+# #+# */
|
||||
/* Updated: 2025/12/09 12:02:28 by mteriier ### ########lyon.fr */
|
||||
/* Updated: 2025/12/09 13:49:13 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,5 +23,5 @@ int check_order(t_stack *stack)
|
||||
return (0);
|
||||
stack = stack->next;
|
||||
}
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
9
main.c
9
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 13:35:44 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/12/09 13:52:43 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -66,10 +66,9 @@ int main(int argc, char **argv)
|
||||
print_all_stack(stacks->a, stacks->a, 'A');
|
||||
print_all_stack(stacks->b, stacks->b, 'B');
|
||||
*/
|
||||
//bubble_alg(stacks);
|
||||
print_stacks(stacks, highest_stack_len(stacks), stacks->a, stacks->b);
|
||||
pb(stacks);
|
||||
print_stacks(stacks, highest_stack_len(stacks), stacks->a, stacks->b);
|
||||
bubble_alg(stacks);
|
||||
//print_stacks(stacks, highest_stack_len(stacks), stacks->a, stacks->b);
|
||||
}
|
||||
stack_clear_all(stacks->a, stacks->a);
|
||||
stack_clear_all(stacks->b, stacks->b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user