Fixed malloc() and pop().
This commit is contained in:
parent
ad737aa765
commit
e72d21f1f0
12
lib/stack.c
12
lib/stack.c
@ -6,7 +6,7 @@
|
|||||||
struct stack *initialize_stack() {
|
struct stack *initialize_stack() {
|
||||||
struct stack *stack = NULL;
|
struct stack *stack = NULL;
|
||||||
|
|
||||||
stack = malloc(sizeof(stack));
|
stack = malloc(sizeof(*stack));
|
||||||
|
|
||||||
stack->card = NULL;
|
stack->card = NULL;
|
||||||
stack->next = NULL;
|
stack->next = NULL;
|
||||||
@ -46,13 +46,13 @@ void push(struct stack **stack, struct card *card) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stack *pop(struct stack *stack) {
|
struct stack *pop(struct stack **stack) {
|
||||||
struct stack *popped_entry = NULL;
|
struct stack *popped_entry = NULL;
|
||||||
|
|
||||||
if(!empty(stack)) {
|
if(!empty(*stack)) {
|
||||||
popped_entry = stack;
|
popped_entry = *stack;
|
||||||
popped_entry = NULL;
|
*stack = (*stack)->next;
|
||||||
stack = stack->next;
|
popped_entry->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(popped_entry);
|
return(popped_entry);
|
||||||
|
@ -10,6 +10,6 @@ struct stack *initialize_stack();
|
|||||||
bool empty(struct stack *);
|
bool empty(struct stack *);
|
||||||
int length(struct stack *);
|
int length(struct stack *);
|
||||||
void push(struct stack **, struct card *);
|
void push(struct stack **, struct card *);
|
||||||
struct stack *pop(struct stack *);
|
struct stack *pop(struct stack **);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user