diff --git a/stack.c b/stack.c index 648063251777015b3d1075c11d9e6992fce48fc8..183570051fd02310aa89db9b224ed6b94279cd97 100644 --- a/stack.c +++ b/stack.c @@ -17,6 +17,20 @@ void stack_peek(stack s, int *value){ } } +void stack_print(const stack s) { + //TODO: replace if statement with following as soon as relevant function is implemented + //if (!stack_is_empty()) { + if (s.top >= 0) { + printf(" TOP\n--------------------\n"); + for (int* spot = s.data + s.top; spot >= s.data; --spot) { + printf("%8d | %12d\n", spot - s.data, *spot); + } + printf("--------------------\n BOTTOM\n"); + } else { + printf("STACK EMPTY\n"); + } +} + void stack_clone(stack s, stack *clone) { clone->top = s.top; clone->capacity = s.capacity; @@ -30,3 +44,4 @@ int get_length(stack s) { return s->top + 1; } + diff --git a/stack.h b/stack.h index 384a0a095d9102ab182ff381720ee5db088522cf..fc3bc04697bb7e9e90cd32b17f8e3c161c92247b 100644 --- a/stack.h +++ b/stack.h @@ -13,4 +13,6 @@ void stack_peek(stack s, int *value); void stack_clone(stack s, stack *clone); int get_length(stack s); +void stack_print(const stack s); + #endif