-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.c
47 lines (39 loc) · 1.02 KB
/
demo.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Stack.h"
#include <stdio.h>
typedef struct _Item
{
int a;
double b;
char c;
} Item;
int main(int argc, char **argv)
{
// Initialize data
Stack stack;
stackInit(&stack, sizeof(Item));
const int ints[5] = {10, 20, 30, 40, 50};
const double doubles[5] = {10.1, 10.2, 10.3, 10.4, 10.5};
const char chars[5] = {'a', 'b', 'c', 'd', 'e'};
printf("\n");
// Push items
for (int i = 0; i < 5; ++i)
{
Item item = {ints[i], doubles[i], chars[i]};
printf("Pushing {item.a: %d, item.b: %.1f, item.c: %c}\n", item.a, item.b, item.c);
stackPush(&stack, &item);
}
printf("\nStack size is %lu\n\n", stackSize(&stack));
// Pop items
for (int i = 0; i < 5; ++i)
{
Item item;
stackPop(&stack, &item);
printf("Popping {item.a: %d, item.b: %.1f, item.c: %c}\n", item.a, item.b, item.c);
}
printf("\nStack is empty? ");
if (stackEmpty(&stack))
printf("Yes\n\n");
else
printf("No\n\n");
return 0;
}