From: Dominik Kaiser Date: Sat, 13 Apr 2024 18:01:38 +0000 (+0200) Subject: Create function for step-by-step sorting X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=3d5057371652145189cbf643d99f8628932e1615;p=42%2Fpush_swap.git Create function for step-by-step sorting --- diff --git a/sorting.c b/sorting.c index ff825b6..6790fa2 100644 --- a/sorting.c +++ b/sorting.c @@ -6,44 +6,48 @@ /* By: dkaiser content >> bit) % 2 == 0) + run_command(stack_a, stack_b, cmds, PB); + else if ((*stack_a)->next) + run_command(stack_a, stack_b, cmds, RA); + i++; + } + while (*stack_b) + run_command(stack_a, stack_b, cmds, PA); +} -static void stack_radixsort(t_list **stack_a, t_list **stack_b, t_list **cmds) +static void stack_radixsort(t_list **stack_a, t_list **stack_b, t_list **cmds) { - int bit; - int max; - int i; - int max_bits; - - bit = 0; - max_bits = 9; + int bit; + int max_bits; - while (bit < max_bits) - { - i = 0; - max = ft_lstsize(*stack_a); - while (i < max) - { - if (*stack_a && (*(int *)(*stack_a)->content >> bit) % 2 == 0) - run_command(stack_a, stack_b, cmds, PB); - else if ((*stack_a)->next) - run_command(stack_a, stack_b, cmds, RA); - i++; - } - while (*stack_b) - run_command(stack_a, stack_b, cmds, PA); - bit++; - } + bit = 0; + max_bits = 9; + while (bit < max_bits) + { + radixsort_step(stack_a, stack_b, cmds, bit); + bit++; + } } -void stack_sort(t_list **stack_a, t_list **stack_b, t_list **cmds) +void stack_sort(t_list **stack_a, t_list **stack_b, t_list **cmds) { - stack_radixsort(stack_a, stack_b, cmds); + stack_radixsort(stack_a, stack_b, cmds); }