Fixed malloc() and pop().

This commit is contained in:
Murilo Soares Pereira 2010-04-04 04:15:43 -03:00
parent ad737aa765
commit e72d21f1f0
2 changed files with 7 additions and 7 deletions

View File

@ -6,7 +6,7 @@
struct stack *initialize_stack() {
struct stack *stack = NULL;
stack = malloc(sizeof(stack));
stack = malloc(sizeof(*stack));
stack->card = 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;
if(!empty(stack)) {
popped_entry = stack;
popped_entry = NULL;
stack = stack->next;
if(!empty(*stack)) {
popped_entry = *stack;
*stack = (*stack)->next;
popped_entry->next = NULL;
}
return(popped_entry);

View File

@ -10,6 +10,6 @@ struct stack *initialize_stack();
bool empty(struct stack *);
int length(struct stack *);
void push(struct stack **, struct card *);
struct stack *pop(struct stack *);
struct stack *pop(struct stack **);
#endif