Fixed push().

This commit is contained in:
Murilo Soares Pereira 2010-04-04 03:20:56 -03:00
parent 84383a3275
commit ad737aa765
2 changed files with 7 additions and 7 deletions

View File

@ -33,16 +33,16 @@ int length(struct stack *stack) {
return(length); return(length);
} }
void push(struct stack *stack, struct card *card) { void push(struct stack **stack, struct card *card) {
struct stack *new_stack = NULL; struct stack *new_stack = NULL;
if (empty(stack)) { if (empty(*stack)) {
stack->card = card; (*stack)->card = card;
} else { } else {
new_stack = malloc(sizeof(new_stack)); new_stack = initialize_stack();
new_stack->card = card; new_stack->card = card;
new_stack->next = stack; new_stack->next = (*stack);
stack = new_stack; *stack = new_stack;
} }
} }

View File

@ -9,7 +9,7 @@ struct stack {
struct stack *initialize_stack(); 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