File tree 2 files changed +12
-12
lines changed
2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -5,28 +5,28 @@ struct node {
5
5
node *next;
6
6
};
7
7
8
- node *top_var ;
8
+ node *stack_idx ;
9
9
10
10
void push (int x) {
11
11
node *n = new node;
12
12
n->val = x;
13
- n->next = top_var ;
14
- top_var = n;
13
+ n->next = stack_idx ;
14
+ stack_idx = n;
15
15
}
16
16
17
17
void pop () {
18
- if (top_var == NULL ) {
18
+ if (stack_idx == NULL ) {
19
19
std::cout << " \n Underflow" ;
20
20
} else {
21
- node *t = top_var ;
21
+ node *t = stack_idx ;
22
22
std::cout << " \n " << t->val << " deleted" ;
23
- top_var = top_var ->next ;
23
+ stack_idx = stack_idx ->next ;
24
24
delete t;
25
25
}
26
26
}
27
27
28
28
void show () {
29
- node *t = top_var ;
29
+ node *t = stack_idx ;
30
30
while (t != NULL ) {
31
31
std::cout << t->val << " \n " ;
32
32
t = t->next ;
Original file line number Diff line number Diff line change 20
20
char stack[MAX];
21
21
22
22
// ! pointer to track stack index
23
- int top_var = -1 ;
23
+ int stack_idx = -1 ;
24
24
25
25
// ! push byte to stack variable
26
- void push (char ch) { stack[++top_var ] = ch; }
26
+ void push (char ch) { stack[++stack_idx ] = ch; }
27
27
28
28
// ! pop a byte out of stack variable
29
- char pop () { return stack[top_var --]; }
29
+ char pop () { return stack[stack_idx --]; }
30
30
31
31
// ! @}-------------- end stack -----------
32
32
@@ -56,7 +56,7 @@ int main() {
56
56
while (valid == 1 && i < exp .length ()) {
57
57
if (exp [i] == ' (' || exp [i] == ' {' || exp [i] == ' [' || exp [i] == ' <' ) {
58
58
push (exp [i]);
59
- } else if (top_var >= 0 && stack[top_var ] == opening (exp [i])) {
59
+ } else if (stack_idx >= 0 && stack[stack_idx ] == opening (exp [i])) {
60
60
pop ();
61
61
} else {
62
62
valid = 0 ;
@@ -65,7 +65,7 @@ int main() {
65
65
}
66
66
67
67
// makes sure the stack is empty after processsing (above)
68
- if (valid == 1 && top_var == -1 ) {
68
+ if (valid == 1 && stack_idx == -1 ) {
69
69
std::cout << " \n Correct Expression" ;
70
70
} else {
71
71
std::cout << " \n Wrong Expression" ;
You can’t perform that action at this time.
0 commit comments