-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
65 lines (49 loc) · 1.28 KB
/
example.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Stack.h"
int main(int argc, char** argv)
{
// Create a stack of capacity 5
Stack* stack = newStack(5);
// Push items to stack
push(stack, 1);
push(stack, 2);
push(stack, 3);
push(stack, 4);
push(stack, 5);
push(stack, 100);
// Check if stack is full
if (isFull(stack)) {
printf("Stack is full!\n");
}
// Print the stack
printStack(stack);
// Resize the stack
stack = resizeStack(stack, 10);
// Push an item to stack
push(stack, 100);
// Print the stack
printStack(stack);
// Pop items from stack
pop(stack);
pop(stack);
// Convert the stack to string
char* str = stackToString(stack);
printf("%s\n", str);
// Check if the stack is empty
if (isEmpty(stack)) {
printf("Stack is empty!\n");
} else {
printf("Stack is not empty!\n");
}
// Peek the top item from stack
printf("Top item: %d\n", peek(stack));
// Destroy the stack
destroyStack(stack);
printf("%s\n", stackToString(stack));
// Check if the stack is empty
if (isEmpty(stack)) {
printf("Stack is empty!\n");
} else {
printf("Stack is not empty!\n");
}
return 0;
}