summaryrefslogtreecommitdiff
path: root/sorting.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-04-13 15:31:29 +0200
committerDominik Kaiser2024-04-13 15:31:29 +0200
commit9674332f03f434534017c0f70f3c213fa4ebb2bf (patch)
tree09c455e40cb2ca91021ced93ceb8e827dba4ba54 /sorting.c
parent9585e1d336c6a1581b335798762172314de1fefb (diff)
downloadpush_swap-9674332f03f434534017c0f70f3c213fa4ebb2bf.tar.gz
push_swap-9674332f03f434534017c0f70f3c213fa4ebb2bf.zip
Add radixsort
Diffstat (limited to 'sorting.c')
-rw-r--r--sorting.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/sorting.c b/sorting.c
index 3624ae5..135a94d 100644
--- a/sorting.c
+++ b/sorting.c
@@ -6,13 +6,39 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/13 15:04:19 by dkaiser #+# #+# */
-/* Updated: 2024/04/13 15:06:33 by dkaiser ### ########.fr */
+/* Updated: 2024/04/13 15:17:26 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft/libft.h"
#include "push_swap.h"
-void stack_sort(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;
+
+ bit = 0;
+ while (bit < 9)
+ {
+ i = 0;
+ max = ft_lstsize(*stack_a);
+ while (i < max)
+ {
+ if ((*(int *)(*stack_a)->content >> bit) % 2 == 0)
+ run_command(stack_a, stack_b, cmds, PB);
+ else
+ run_command(stack_a, stack_b, cmds, RA);
+ i++;
+ }
+ while (*stack_b)
+ run_command(stack_a, stack_b, cmds, PA);
+ bit++;
+ }
+}
+void stack_sort(t_list **stack_a, t_list **stack_b, t_list **cmds)
+{
+ stack_radixsort(stack_a, stack_b, cmds);
}