Change return type of stack_push from void
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 29 Feb 2024 09:29:12 +0000 (10:29 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 29 Feb 2024 09:29:12 +0000 (10:29 +0100)
Previously the return type was void as handling any error was percieved
as too annoying and action_push must have been void anyway.
This change is done for future changes that may benefit from the
information of error, while the return value is ignored in the
functions that expect void.

src/checker.h
src/stack_manipulation.c

index 52e74bfbef149e0e51e99c6e0c77b9634b951410..2288d796bb133fbe8b618ea84d9bc64f324f0dae 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/01/24 12:13:51 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/02/24 14:06:52 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/02/29 10:27:01 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -42,8 +42,8 @@ typedef struct s_command
        t_target        target;
 }                              t_command;
 
-void   init_stack(t_stack *s);
-void   clean_up(t_stacks *s);
+void           init_stack(t_stack *s);
+void           clean_up(t_stacks *s);
 /*
 t_action       action_push;
 t_action       action_swap;
@@ -51,27 +51,27 @@ t_action    action_rotate;
 t_action       action_reverse_rotate;
 */
 
-void   action_push(t_stacks *s, t_target target);
-void   action_swap(t_stacks *s, t_target target);
-void   action_rotate(t_stacks *s, t_target target);
-void   action_reverse_rotate(t_stacks *s, t_target target);
+void           action_push(t_stacks *s, t_target target);
+void           action_swap(t_stacks *s, t_target target);
+void           action_rotate(t_stacks *s, t_target target);
+void           action_reverse_rotate(t_stacks *s, t_target target);
 
-void   print_push(t_stacks *s, t_target target);
-void   print_swap(t_stacks *s, t_target target);
-void   print_rotate(t_stacks *s, t_target target);
-void   print_reverse_rotate(t_stacks *s, t_target target);
+void           print_push(t_stacks *s, t_target target);
+void           print_swap(t_stacks *s, t_target target);
+void           print_rotate(t_stacks *s, t_target target);
+void           print_reverse_rotate(t_stacks *s, t_target target);
 
-void   stack_push(t_stack *s, int el);
-void   stack_swap(t_stack *s);
-void   stack_rotate(t_stack *s, int amount);
-void   stack_pop(t_stack *s);
-int            stack_top(t_stack *s);
+t_arr_stat     stack_push(t_stack *s, int el);
+void           stack_swap(t_stack *s);
+void           stack_rotate(t_stack *s, int amount);
+void           stack_pop(t_stack *s);
+int                    stack_top(t_stack *s);
 
-int            is_sorted(t_stack *s);
-int            parse(int argc, char **argv, t_stack *s);
-void   prepare_stacks(t_stacks *s, size_t ind_a, size_t ind_b);
-size_t cost(t_stacks *s, const size_t b_plus, const size_t a_plus);
-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);
+int                    is_sorted(t_stack *s);
+int                    parse(int argc, char **argv, t_stack *s);
+void           prepare_stacks(t_stacks *s, size_t ind_a, size_t ind_b);
+size_t         cost(t_stacks *s, const size_t b_plus, const size_t a_plus);
+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);
 #endif //CHECKER_H
index 5003b62672f880ead114a7c98f9ce1ac5b80a0f0..dbc64b1f5e5e1973e17eab2f4c7efd748fe0e78d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/01/24 11:48:47 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/01/24 13:59:25 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/02/29 10:25:56 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -46,10 +46,9 @@ void stack_pop(t_stack *s)
        return ;
 }
 
-void   stack_push(t_stack *s, int el)
+t_arr_stat     stack_push(t_stack *s, int el)
 {
-       ft_vec_insert(&s->stack, &el, s->ind);
-       return ;
+       return (ft_vec_insert(&s->stack, &el, s->ind));
 }
 
 void   stack_swap(t_stack *s)