Skip to content

Commit b6fdaa6

Browse files
committed
docs: Change variable names
1 parent f05aadf commit b6fdaa6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

data_structures/stack_using_linked_list.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ struct node {
55
node *next;
66
};
77

8-
node *top_var;
8+
node *stack_idx;
99

1010
void push(int x) {
1111
node *n = new node;
1212
n->val = x;
13-
n->next = top_var;
14-
top_var = n;
13+
n->next = stack_idx;
14+
stack_idx = n;
1515
}
1616

1717
void pop() {
18-
if (top_var == NULL) {
18+
if (stack_idx == NULL) {
1919
std::cout << "\nUnderflow";
2020
} else {
21-
node *t = top_var;
21+
node *t = stack_idx;
2222
std::cout << "\n" << t->val << " deleted";
23-
top_var = top_var->next;
23+
stack_idx = stack_idx->next;
2424
delete t;
2525
}
2626
}
2727

2828
void show() {
29-
node *t = top_var;
29+
node *t = stack_idx;
3030
while (t != NULL) {
3131
std::cout << t->val << "\n";
3232
t = t->next;

others/paranthesis_matching.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
char stack[MAX];
2121

2222
//! pointer to track stack index
23-
int top_var = -1;
23+
int stack_idx = -1;
2424

2525
//! push byte to stack variable
26-
void push(char ch) { stack[++top_var] = ch; }
26+
void push(char ch) { stack[++stack_idx] = ch; }
2727

2828
//! pop a byte out of stack variable
29-
char pop() { return stack[top_var--]; }
29+
char pop() { return stack[stack_idx--]; }
3030

3131
//! @}-------------- end stack -----------
3232

@@ -56,7 +56,7 @@ int main() {
5656
while (valid == 1 && i < exp.length()) {
5757
if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') {
5858
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])) {
6060
pop();
6161
} else {
6262
valid = 0;
@@ -65,7 +65,7 @@ int main() {
6565
}
6666

6767
// makes sure the stack is empty after processsing (above)
68-
if (valid == 1 && top_var == -1) {
68+
if (valid == 1 && stack_idx == -1) {
6969
std::cout << "\nCorrect Expression";
7070
} else {
7171
std::cout << "\nWrong Expression";

0 commit comments

Comments
 (0)