NAME=push_swap
-SRCS=algorithm_quicksort.c cheatalloc.c clist.c list.c main_pushswap.c op_output.c op_p.c op_r.c op_rr.c op_s.c ops.c ops_groups.c ops_optimizer.c output.c psval.c stack.c stacks.c
+SRCS=algorithm_quicksort.c algorithm_selection_sort.c cheatalloc.c clist.c list.c main_pushswap.c op_output.c op_p.c op_r.c op_rr.c op_s.c ops.c ops_groups.c ops_optimizer.c output.c psval.c stack.c stacks.c
OBJS=${SRCS:%.c=${OBJDIR}/%.o}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* algorithm_selection_sort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/12/09 15:43:09 by clefrere #+# #+# */
+/* Updated: 2025/12/09 15:59:47 by clefrere ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "pushswap.h"
+
+void algorithm_selection_sort(const t_stacks *stacks, t_closure cb)
+{
+ t_list sorted;
+
+ sorted = list_new(stacks->a);
+ list_sort(sorted);
+ while (sorted.len)
+ {
+ if (stacks->a.list->val == sorted.ptr[0])
+ {
+ (cb.func)(cb.data, OP_PB);
+ sorted = list_sub(sorted, 1, sorted.len);
+ }
+ else
+ (cb.func)(cb.data, OP_RA);
+ }
+ while (stacks->b.len)
+ (cb.func)(cb.data, OP_PA);
+}
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 22:15:12 by agilliar #+# #+# */
-/* Updated: 2025/12/08 20:22:37 by agilliar ### ########.fr */
+/* Updated: 2025/12/09 16:06:44 by clefrere ### ########.fr */
/* */
/* ************************************************************************** */
static void arg_step(char *str, t_args *arg)
{
if (ft_streq(str, "--simple"))
- arg->algo = NULL;
+ arg->algo = &algorithm_selection_sort;
else if (ft_streq(str, "--medium"))
arg->algo = NULL;
else if (ft_streq(str, "--complex"))
/* ::: :::::::: */
/* pushswap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
-/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
+/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 11:02:44 by agilliar #+# #+# */
-/* Updated: 2025/12/09 14:50:45 by agilliar ### ########.fr */
+/* Updated: 2025/12/09 15:54:48 by clefrere ### ########.fr */
/* */
/* ************************************************************************** */
t_list list_sub(t_list self, size_t start, size_t end);
void list_sort(t_list list);
+void algorithm_selection_sort(const t_stacks *stacks, t_closure cb);
void algorithm_quicksort(const t_stacks *stacks, t_closure cb);
#endif