Skip to content
Snippets Groups Projects
Commit e66d9cd7 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: stack_print: add special case for empty stack

parent a27837de
No related branches found
No related tags found
1 merge request!12Add stack_print(stack) function
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
......@@ -18,9 +18,13 @@ void stack_peek(stack s, int *value){
}
void stack_print(const stack s) {
printf(" TOP\n--------------------\n");
for (int* spot = s.data + s.top; spot >= s.data; --spot) {
printf("%8d | %12d\n", spot - s.data, *spot);
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");
}
printf("--------------------\n BOTTOM\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment