]> git.dkaiser.de - 42/push_swap.git/commitdiff
Change to 3-way radixsort
authorDominik Kaiser <dominik@dominik-XPS.fritz.box>
Wed, 17 Apr 2024 07:48:09 +0000 (09:48 +0200)
committerDominik Kaiser <dominik@dominik-XPS.fritz.box>
Wed, 17 Apr 2024 07:48:09 +0000 (09:48 +0200)
Instead of splitting into 2 sets, radixsort will split into 3.
Currently one set is half and the other two each a quarter.
Probably the efficiency could be increased by 3 equal partitions.
Will look into that later.

sorting.c

index 422625e5b79b78d3e4ce2da288d9d7ec28ebc0c1..215f4a45050bf3d8d0f351517dec09edea4ff696 100644 (file)
--- a/sorting.c
+++ b/sorting.c
@@ -6,7 +6,7 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/04/13 15:04:19 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/04/16 17:54:16 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/04/17 09:30:37 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -33,17 +33,33 @@ static void radixsort(t_psdata *data, int bit)
 {
     int i;
     int size;
+    int ctr;
 
     i = 0;
+    ctr = 0;
     size = data->a->size;
     while (i < size)
     {
         if (data->a->size && ((data->a->stack[0] >> bit) & 1) == 0)
-            run_command(data, PB);
+        {
+            if (((data->a->stack[0] >> bit )& 2) == 0)
+                run_command(data, PB);
+            else
+            {
+                run_command(data, PB);
+                run_command(data, RB);
+                ctr++;
+            }
+        }
         else if (data->a->size > 1)
             run_command(data, RA);
         i++;
     }
+    while (ctr--)
+    {
+        run_command(data, RRB);
+        run_command(data, PA);
+    }
     while (data->b->size > 0)
         run_command(data, PA);
     if (!is_sorted(data->a))