Really, don't change the stack when calling stack#reverse.

This commit is contained in:
Murilo Pereira
2011-05-01 02:04:16 -03:00
parent 0e0c44f5c6
commit 0a37b5982a
2 changed files with 8 additions and 6 deletions

View File

@@ -97,12 +97,12 @@ struct stack *pop(struct stack **stack) {
struct stack *reverse(struct stack *stack) {
if (length(stack) > 1) {
struct stack *tmp_stack;
struct stack *tmp_stack, *iterator;
allocate_stack(&tmp_stack);
initialize_stack(tmp_stack);
while (!empty(stack)) {
push(&tmp_stack, pop((&stack))->card);
for (iterator = stack; iterator; iterator = iterator->next) {
push(&tmp_stack, iterator->card);
}
return(tmp_stack);
} else {