prepare.c \
find.c \
circular_lis.c \
+ special_a.c \
PUSHSOURCES := $(addprefix $(PUSHSRCDIR)/, $(PUSHSOURCES))
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/24 12:13:51 by ljiriste #+# #+# */
-/* Updated: 2024/02/29 16:27:28 by ljiriste ### ########.fr */
+/* Updated: 2024/03/01 09:49:02 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
size_t find_best(t_stacks *s, t_vec *target_a_indeces);
size_t find_target_ind(t_stack *stack, int val);
size_t find_minind(t_stack *s);
+void rotate_a_to_sort(t_stacks *s);
+void isolate_lis_in_a(t_stacks *s, t_stack *lis);
+void a_sort_three_or_less(t_stacks *s);
#endif //CHECKER_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/27 15:18:21 by ljiriste #+# #+# */
-/* Updated: 2024/02/29 16:59:55 by ljiriste ### ########.fr */
+/* Updated: 2024/03/01 09:59:03 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "checker.h"
#include "libft.h"
-static t_arr_stat reconstruct_lis(t_stack *lis, t_stack *stack, t_vec *lowest, t_vec *predecessors)
+static t_arr_stat reconstruct_lis(t_stack *lis, t_stack *stack,
+ t_vec *lowest, t_vec *predecessors)
{
size_t i;
size_t j;
return (success);
}
-static t_arr_stat get_lis_loop(t_stack *stack, t_vec *inds_of_lowest, t_vec *inds_of_predecessor)
+static t_arr_stat get_lis_loop(t_stack *stack, t_vec *inds_of_lowest,
+ t_vec *inds_of_predecessor)
{
size_t i;
size_t new_ind;
else
*(size_t *)ft_vec_access(inds_of_lowest, new_ind) = i;
if (res != success)
- break;
+ break ;
if (new_ind == 0)
res = ft_vec_append(inds_of_predecessor, &invalid);
else
- res = ft_vec_append(inds_of_predecessor, ft_vec_access(inds_of_lowest, new_ind - 1));
+ res = ft_vec_append(inds_of_predecessor,
+ ft_vec_access(inds_of_lowest, new_ind - 1));
if (res != success)
- break;
+ break ;
++i;
}
return (res);
/* This is the algorithm for finding the longest increasing subsequence
found on wikipedia adjusted for circular sequences (stack).*/
-static t_arr_stat get_lis(t_stack *lis, t_stack *stack, size_t ind)
+static t_arr_stat get_lis(t_stack *lis, t_stack *stack, size_t ind)
{
t_vec inds_of_lowest;
t_vec inds_of_predecessor;
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/22 14:22:08 by ljiriste #+# #+# */
-/* Updated: 2024/02/29 16:20:32 by ljiriste ### ########.fr */
+/* Updated: 2024/03/01 09:59:03 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
mid = lo + (hi - lo) / 2;
while (lo != hi)
{
- if (val > unrolled_stack_access(stack, *(size_t *)ft_vec_access(sorted, mid)))
+ if (val > unrolled_stack_access(stack,
+ *(size_t *)ft_vec_access(sorted, mid)))
{
lo = mid + 1;
}
}
return (mid);
}
-
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/24 13:17:32 by ljiriste #+# #+# */
-/* Updated: 2024/02/29 14:41:41 by ljiriste ### ########.fr */
+/* Updated: 2024/03/01 09:59:04 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "checker.h"
#include "libft.h"
-#include <limits.h>
#include <stddef.h>
-void a_sort_three_or_less(t_stacks *s)
-{
- int last;
- int max;
- size_t steps_to_smaller;
- size_t i;
-
- i = 0;
- last = stack_top(&s->a);
- max = INT_MIN;
- steps_to_smaller = 0;
- while (i < s->a.stack.size)
- {
- stack_rotate(&s->a, 1);
- steps_to_smaller += (stack_top(&s->a) < last);
- last = stack_top(&s->a);
- if (max < stack_top(&s->a))
- max = stack_top(&s->a);
- ++i;
- }
- if (steps_to_smaller == 2)
- print_swap(s, a);
- return ;
-}
-
void get_push_indeces(t_stacks *s, int *ind_a, int *ind_b)
{
t_vec target_a_indeces;
return ;
}
-void rotate_a_to_sort(t_stacks *s)
-{
- size_t minind;
- t_action *print_action;
-
- minind = find_minind(&s->a);
- if (minind <= s->a.stack.size / 2)
- print_action = print_rotate;
- else
- {
- minind -= s->a.stack.size / 2;
- print_action = print_reverse_rotate;
- }
- while (minind > 0)
- {
- print_action(s, a);
- --minind;
- }
- return ;
-}
-
void sort(t_stacks *s)
{
int ind_a;
init_stack(&lis);
get_circular_lis(&lis, &s->a);
- while (s->a.stack.size > lis.stack.size && s->a.stack.size > 3)
- {
- if (stack_top(&lis) == stack_top(&s->a))
- {
- stack_rotate(&lis, 1);
- print_rotate(s, a);
- }
- else
- print_push(s, b);
- }
+ isolate_lis_in_a(s, &lis);
free_stack(&lis);
if (lis.stack.size < 3)
a_sort_three_or_less(s);
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* special_a.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/01 09:45:01 by ljiriste #+# #+# */
+/* Updated: 2024/03/01 09:59:04 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "checker.h"
+#include "libft.h"
+#include <limits.h>
+#include <stddef.h>
+
+void rotate_a_to_sort(t_stacks *s)
+{
+ size_t minind;
+ t_action *print_action;
+
+ minind = find_minind(&s->a);
+ if (minind <= s->a.stack.size / 2)
+ print_action = print_rotate;
+ else
+ {
+ minind -= s->a.stack.size / 2;
+ print_action = print_reverse_rotate;
+ }
+ while (minind > 0)
+ {
+ print_action(s, a);
+ --minind;
+ }
+ return ;
+}
+
+void isolate_lis_in_a(t_stacks *s, t_stack *lis)
+{
+ while (s->a.stack.size > lis->stack.size && s->a.stack.size > 3)
+ {
+ if (stack_top(lis) == stack_top(&s->a))
+ {
+ stack_rotate(lis, 1);
+ print_rotate(s, a);
+ }
+ else
+ print_push(s, b);
+ }
+ return ;
+}
+
+void a_sort_three_or_less(t_stacks *s)
+{
+ int last;
+ int max;
+ size_t steps_to_smaller;
+ size_t i;
+
+ i = 0;
+ last = stack_top(&s->a);
+ max = INT_MIN;
+ steps_to_smaller = 0;
+ while (i < s->a.stack.size)
+ {
+ stack_rotate(&s->a, 1);
+ steps_to_smaller += (stack_top(&s->a) < last);
+ last = stack_top(&s->a);
+ if (max < stack_top(&s->a))
+ max = stack_top(&s->a);
+ ++i;
+ }
+ if (steps_to_smaller == 2)
+ print_swap(s, a);
+ return ;
+}