From b7327f66705df6aa164206b3bfbc59526a8370e9 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Tue, 5 Mar 2024 13:57:27 +0100 Subject: [PATCH] Make the code check if input is already sorted ... and not sort it in that case This is only needed because the program doesn't use LIS for inputs smaller than 7 elements. --- src/push.c | 5 +++-- src/special_a.c | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/push.c b/src/push.c index ac06c0b..c2b7e47 100644 --- a/src/push.c +++ b/src/push.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/24 13:17:32 by ljiriste #+# #+# */ -/* Updated: 2024/03/05 11:54:36 by ljiriste ### ########.fr */ +/* Updated: 2024/03/05 13:43:48 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,7 +89,8 @@ int main(int argc, char **argv) ft_dprintf(STDERR_FILENO, "Error.\n"); return (1); } - sort(&s); + if (!is_sorted(&s.a)) + sort(&s); clean_up(&s); return (0); } diff --git a/src/special_a.c b/src/special_a.c index ea941bc..02feb46 100644 --- a/src/special_a.c +++ b/src/special_a.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/01 09:45:01 by ljiriste #+# #+# */ -/* Updated: 2024/03/01 12:45:54 by ljiriste ### ########.fr */ +/* Updated: 2024/03/05 13:56:47 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,10 @@ void rotate_a_to_sort(t_stacks *s) return ; } +// Could be improved by deciding whether to isolate using +// rotate or reverse_rotate +// Example: 1 2 3 4 5 6 8 7 +// rotates basically through the whole stack void isolate_lis_in_a(t_stacks *s, t_stack *lis) { while (s->a.stack.size > lis->stack.size && s->a.stack.size > 3) -- 2.30.2