docs: Change variable names

This commit is contained in:
Panquesito7 2020-06-23 18:45:56 -05:00
parent f05aadf3b8
commit b6fdaa63eb
No known key found for this signature in database
GPG Key ID: 3C482B03FD220E68
2 changed files with 12 additions and 12 deletions

View File

@ -5,28 +5,28 @@ struct node {
node *next; node *next;
}; };
node *top_var; node *stack_idx;
void push(int x) { void push(int x) {
node *n = new node; node *n = new node;
n->val = x; n->val = x;
n->next = top_var; n->next = stack_idx;
top_var = n; stack_idx = n;
} }
void pop() { void pop() {
if (top_var == NULL) { if (stack_idx == NULL) {
std::cout << "\nUnderflow"; std::cout << "\nUnderflow";
} else { } else {
node *t = top_var; node *t = stack_idx;
std::cout << "\n" << t->val << " deleted"; std::cout << "\n" << t->val << " deleted";
top_var = top_var->next; stack_idx = stack_idx->next;
delete t; delete t;
} }
} }
void show() { void show() {
node *t = top_var; node *t = stack_idx;
while (t != NULL) { while (t != NULL) {
std::cout << t->val << "\n"; std::cout << t->val << "\n";
t = t->next; t = t->next;

View File

@ -20,13 +20,13 @@
char stack[MAX]; char stack[MAX];
//! pointer to track stack index //! pointer to track stack index
int top_var = -1; int stack_idx = -1;
//! push byte to stack variable //! 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 //! pop a byte out of stack variable
char pop() { return stack[top_var--]; } char pop() { return stack[stack_idx--]; }
//! @}-------------- end stack ----------- //! @}-------------- end stack -----------
@ -56,7 +56,7 @@ int main() {
while (valid == 1 && i < exp.length()) { while (valid == 1 && i < exp.length()) {
if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') { if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[' || exp[i] == '<') {
push(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(); pop();
} else { } else {
valid = 0; valid = 0;
@ -65,7 +65,7 @@ int main() {
} }
// makes sure the stack is empty after processsing (above) // 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"; std::cout << "\nCorrect Expression";
} else { } else {
std::cout << "\nWrong Expression"; std::cout << "\nWrong Expression";