Make the code check if input is already sorted
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 5 Mar 2024 12:57:27 +0000 (13:57 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 5 Mar 2024 12:57:27 +0000 (13:57 +0100)
... 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
src/special_a.c

index ac06c0bafe6cdf06ca15cf89425a3e575e67cfea..c2b7e478768d57fa4eb1235514ed288075d3ce3b 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);
 }
index ea941bccce9c5830c2e1ec30755b2c864b0a5688..02feb46d85e3d59b9c3a23a91f2224b1c728b8b9 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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)