-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_test.c
31 lines (26 loc) · 898 Bytes
/
stack_test.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
#include <stdio.h>
#include "stack_test.h"
#include "stack.h"
#include "item.h"
bool TestStack(void)
{
Stack *stack;
InitStack(&stack, sizeof(Item), FreeItem);
for (register int i = 1; i < 10; i++) {
double number = rand()/100.0;
Item *newItem;
MakeItem(&newItem, i, number);
PushStackItem(stack, newItem);
printf("push item to stack: %d %f %d\n", i, number, stack->len);
}
Item tmpItem;
PopStackItem(stack, &tmpItem);
printf("pop item from stack: %d %f %d\n", tmpItem.id, tmpItem.number, stack->len);
PopStackItem(stack, &tmpItem);
printf("pop item from stack: %d %f %d\n", tmpItem.id, tmpItem.number, stack->len);
PopStackItem(stack, &tmpItem);
printf("pop item from stack: %d %f %d\n", tmpItem.id, tmpItem.number, stack->len);
TraverseStack(stack, DisplayItem);
FreeStack(stack);
return true;
}