From 7a6533373ab9b0dd075f995c98dcf332a7876fac Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 10 Sep 2021 10:54:12 +0200 Subject: Updated to norm v3 --- src/common/stack_core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/common/stack_core.c') diff --git a/src/common/stack_core.c b/src/common/stack_core.c index adab5b1..68f74ca 100644 --- a/src/common/stack_core.c +++ b/src/common/stack_core.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 06:37:45 by cacharle #+# #+# */ -/* Updated: 2020/01/22 10:23:18 by cacharle ### ########.fr */ +/* Updated: 2021/09/10 10:32:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,13 @@ t_stack *stack_new(int size) { - t_stack *stack; + t_stack *stack; - if ((stack = (t_stack*)malloc(sizeof(t_stack))) == NULL) + stack = (t_stack *)malloc(sizeof(t_stack)); + if (stack == NULL) return (NULL); - if ((stack->elements = (int*)malloc(sizeof(int) * size)) == NULL) + stack->elements = (int *)malloc(sizeof(int) * size); + if (stack->elements == NULL) { free(stack); return (NULL); @@ -28,12 +30,13 @@ t_stack *stack_new(int size) return (stack); } -void stack_destroy(t_stack *stack) +int stack_destroy(t_stack *stack) { if (stack == NULL) - return ; + return (1); free(stack->elements); free(stack); + return (1); } void stack_push(t_stack *stack, int n) @@ -49,7 +52,7 @@ void stack_pop(t_stack *stack) stack->top--; } -int stack_peek(t_stack *stack) +int stack_peek(t_stack *stack) { if (stack_empty(stack)) return (0); -- cgit