From ad737aa765269e7fa1a56d64e110f3cb7f24728b Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Sun, 4 Apr 2010 03:20:56 -0300 Subject: [PATCH] Fixed push(). --- lib/stack.c | 12 ++++++------ lib/stack.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/stack.c b/lib/stack.c index deba919..60a25ca 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -33,16 +33,16 @@ int length(struct stack *stack) { return(length); } -void push(struct stack *stack, struct card *card) { +void push(struct stack **stack, struct card *card) { struct stack *new_stack = NULL; - if (empty(stack)) { - stack->card = card; + if (empty(*stack)) { + (*stack)->card = card; } else { - new_stack = malloc(sizeof(new_stack)); + new_stack = initialize_stack(); new_stack->card = card; - new_stack->next = stack; - stack = new_stack; + new_stack->next = (*stack); + *stack = new_stack; } } diff --git a/lib/stack.h b/lib/stack.h index abb35b4..e1b8f21 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -9,7 +9,7 @@ struct stack { struct stack *initialize_stack(); bool empty(struct stack *); int length(struct stack *); -void push(struct stack *, struct card *); +void push(struct stack **, struct card *); struct stack *pop(struct stack *); #endif