CC = cc
CFLAGS = -Wall -Wextra -Werror
-SRC_FILES = main.c input_handling.c stack_utils.c command_handling.c
+SRC_FILES = main.c input_handling.c stack_utils.c command_handling.c sorting.c
OBJ_FILES = $(SRC_FILES:%.c=%.o)
LIB_DIR = $(LIBFT)
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/12 17:03:30 by dkaiser #+# #+# */
-/* Updated: 2024/04/13 15:04:10 by dkaiser ### ########.fr */
+/* Updated: 2024/04/13 15:31:05 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
int main(int argc, char *argv[])
{
t_list *stack_a;
- t_list *stack_b;
- t_list *pscmds;
+ t_list *stack_b;
+ t_list *pscmds;
stack_a = create_stack(argc, argv);
if (!stack_a)
{
ft_putendl_fd("Error", 2);
- return 1;
+ return (1);
}
stack_b = NULL;
pscmds = NULL;
-
stack_sort(&stack_a, &stack_b, &pscmds);
-
-
// TODO: Optimize commands
+ print_commands(pscmds);
ft_printf("A:");
ft_lstiter(stack_a, print_content);
ft_printf("\nB:");
ft_lstiter(stack_b, print_content);
- ft_printf("\n\nCMDS:\n");
- print_commands(pscmds);
- return 0;
+ ft_printf("\n");
+ return (0);
}
/* 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);
}