From a27837de9d9b6a16163b93263fbd4f32cb2b91d1 Mon Sep 17 00:00:00 2001 From: Boris Stefanovic <owldev@bluewin.ch> Date: Sat, 27 Nov 2021 15:19:26 +0100 Subject: [PATCH] ADD: stack_print(stack) function --- stack.c | 8 ++++++++ stack.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/stack.c b/stack.c index 2746918..4699c29 100644 --- a/stack.c +++ b/stack.c @@ -16,3 +16,11 @@ void stack_peek(stack s, int *value){ *value = s.data[s.top]; } } + +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); + } + printf("--------------------\n BOTTOM\n"); +} diff --git a/stack.h b/stack.h index 8da80c2..2ae0c05 100644 --- a/stack.h +++ b/stack.h @@ -11,4 +11,6 @@ void stack_init(stack *stack); void stack_peek(stack s, int *value); +void stack_print(const stack s); + #endif -- GitLab