diff --git a/data_structures/stack_using_linked_list.cpp b/data_structures/stack_using_linked_list.cpp index 3dcf03f8a..315b4e3b9 100644 --- a/data_structures/stack_using_linked_list.cpp +++ b/data_structures/stack_using_linked_list.cpp @@ -5,28 +5,28 @@ struct node { node *next; }; -node *top_var; +node *stack_idx; void push(int x) { node *n = new node; n->val = x; - n->next = top_var; - top_var = n; + n->next = stack_idx; + stack_idx = n; } void pop() { - if (top_var == NULL) { + if (stack_idx == NULL) { std::cout << "\nUnderflow"; } else { - node *t = top_var; + node *t = stack_idx; std::cout << "\n" << t->val << " deleted"; - top_var = top_var->next; + stack_idx = stack_idx->next; delete t; } } void show() { - node *t = top_var; + node *t = stack_idx; while (t != NULL) { std::cout << t->val << "\n"; t = t->next; diff --git a/others/paranthesis_matching.cpp b/others/paranthesis_matching.cpp index 0a1a9e474..d9c52c813 100644 --- a/others/paranthesis_matching.cpp +++ b/others/paranthesis_matching.cpp @@ -20,13 +20,13 @@ char stack[MAX]; //! pointer to track stack index -int top_var = -1; +int stack_idx = -1; //! push byte to stack variable -void push(char ch) { stack[++top_var] = ch; } +void push(char ch) { stack[++stack_idx] = ch; } //! pop a byte out of stack variable -char pop() { return stack[top_var--]; } +char pop() { return stack[stack_idx--]; } //! @}-------------- end stack ----------- @@ -56,7 +56,7 @@ int main() { while (valid == 1 && i < exp.length()) { if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') { push(exp[i]); - } else if (top_var >= 0 && stack[top_var] == opening(exp[i])) { + } else if (stack_idx >= 0 && stack[stack_idx] == opening(exp[i])) { pop(); } else { valid = 0; @@ -65,7 +65,7 @@ int main() { } // makes sure the stack is empty after processsing (above) - if (valid == 1 && top_var == -1) { + if (valid == 1 && stack_idx == -1) { std::cout << "\nCorrect Expression"; } else { std::cout << "\nWrong Expression";