summaryrefslogtreecommitdiffstats
path: root/example/stack.c
blob: d5d2e5a25623bad046736af1f5ada618cc64466a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// stack.c - Example usage of stack.h dynamic stack

#include <stdio.h>

typedef double stack_value_t;

#define STACK_IMPLEMENTATION
#include "../include/stack.h"

int main(void) {
  stack_t stack = {0};
  stack.capacity = 10;
  stack_init(&stack);

  for (int i = 0; i < 15; i++) {
    stack_push(&stack, (stack_value_t)i);
  }

  printf("%lf\n", stack_peek(&stack));
  printf("%lf\n", stack_pop(&stack));

  for (int i = 0; i < 14; i++) {
    printf("%lf\n", stack_pop(&stack));
  }

  stack_free(&stack);
}