/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/27 15:18:21 by ljiriste #+# #+# */
-/* Updated: 2024/03/01 10:07:26 by ljiriste ### ########.fr */
+/* Updated: 2024/03/02 12:48:30 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (res);
}
+static void rotate_lis_to_start(t_stack *lis, t_stack *stack, size_t init_ind)
+{
+ while (stack->ind != init_ind)
+ {
+ if (stack_top(lis) == stack_top(stack))
+ stack_rotate(lis, 1);
+ stack_rotate(stack, 1);
+ }
+ return ;
+}
+
/* 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)
stack_rotate(stack, ind);
res = get_lis_loop(stack, &inds_of_lowest, &inds_of_predecessor);
if (res == success)
- reconstruct_lis(lis, stack, &inds_of_lowest, &inds_of_predecessor);
+ {
+ res = reconstruct_lis(lis, stack, &inds_of_lowest, &inds_of_predecessor);
+ if (res == success)
+ rotate_lis_to_start(lis, stack, stack_init_ind);
+ }
ft_vec_free(&inds_of_lowest, NULL);
ft_vec_free(&inds_of_predecessor, NULL);
- stack->ind = stack_init_ind;
return (res);
}
t_arr_stat get_circular_lis(t_stack *lis, t_stack *stack)
{
- size_t max;
- size_t max_ind;
- size_t i;
- size_t len_i;
+ size_t max;
+ size_t max_ind;
+ size_t i;
+ size_t len_i;
+ t_arr_stat res;
max = 0;
i = 0;
++i;
stack_rotate(stack, 1);
}
- return (get_lis(lis, stack, max_ind));
+ res = get_lis(lis, stack, max_ind);
+ return (res);
}