Really, don't change the stack when calling stack#reverse.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user