-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliststacktest.c
More file actions
91 lines (69 loc) · 2.23 KB
/
Copy pathliststacktest.c
File metadata and controls
91 lines (69 loc) · 2.23 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "liststack.h"
static void displayStack(LinkedStack *pStack)
{
StackNode *tmp;
int i = pStack->currentElementCount;
tmp = pStack->pTopElement->preElement;
if (isLinkedStackEmpty(pStack)) printf("\nempty stack\n\n");
while (tmp)
{
printf("|%d's data| [%d]\n", --i, tmp->data);
tmp = tmp->preElement;
}
printf("\n");
}
int main()
{
// LinkedStack *LS = NULL;
// LS = createLinkedStack();
// if (LS != NULL)
// {
// StackNode node;
// printf("---------------- push ----------------\n");
// node.data = 1;
// pushLS(LS, node);
// node.data = 2;
// pushLS(LS, node);
// node.data = 3;
// pushLS(LS, node);
// node.data = 4;
// pushLS(LS, node);
// node.data = 5;
// pushLS(LS, node);
// node.data = 6;
// pushLS(LS, node);
// node.data = 7;
// pushLS(LS, node);
// displayStack(LS);
// printf("---------------- pop ----------------\n");
// //there's memory leaks
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n",popLS(LS)->data);
// printf ("pop element is : %d \n\n",popLS(LS)->data);
// //there's no memory leaks
// // free(popLS(LS));
// // free(popLS(LS));
// // free(popLS(LS));
// // free(popLS(LS));
// // free(popLS(LS));
// // free(popLS(LS));
// // free(popLS(LS));
// displayStack(LS);
// }
// deleteLinkedStack(LS);
// test for checkBracketMatching
char *str_true[4] = { "hi a * ( a + b / {a - b} * ( a * (a + (c+d))) )/ {a b } [ a c b d]",
" ",
" ( [ {{{}}} ] )"};
char *str_false[4] = {"hi a * (( a + b / {a - b} * ( a * (a + (c+d))) )/ {a b } [ a c b d]",
" [ ( { ) ] }",
" ((( )"};
for (int i = 0;str_true[i]; ++i)
printf("result :%d of string :%s \n",checkBracketMatching(str_true[i]), str_true[i]);
for (int i = 0;str_false[i]; ++i)
printf("result :%d of string :%s \n",checkBracketMatching(str_false[i]), str_false[i]);
}