diff options
| author | mo khan <mo.khan@gmail.com> | 2020-07-05 13:21:43 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-07-05 13:21:43 -0600 |
| commit | 15db180b1df02c73dc8632e5ae1eb0f29e2dceaa (patch) | |
| tree | 44a2bec5f32096c1dad6ce38c04e9494d8a70603 /src/01/06/min_stack.c | |
| parent | 313092818159142508866eb975a1d5f6089d9399 (diff) | |
Improve formatted output
Diffstat (limited to 'src/01/06/min_stack.c')
| -rw-r--r-- | src/01/06/min_stack.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/01/06/min_stack.c b/src/01/06/min_stack.c index 816b46d..7567cd6 100644 --- a/src/01/06/min_stack.c +++ b/src/01/06/min_stack.c @@ -38,6 +38,15 @@ void push(Stack *self, int data) { self->size++; } +void each(Node *head, Visitor block) { + Node *tmp = head; + + while(tmp) { + (*block)(tmp); + tmp = tmp->next; + } +} + int min(Stack *self) { if(self->min) return self->min->data; @@ -73,3 +82,15 @@ int pop(Stack *self) { free(current); return data; } + +void print_node(Node *node) +{ + printf("[%d]", node->data); +} + +void inspect(Stack *stack) +{ + printf("\t"); + each(stack->head, &print_node); + printf("\n"); +} |
