Fixed push().
This commit is contained in:
parent
84383a3275
commit
ad737aa765
12
lib/stack.c
12
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user