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 *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;

View File

@ -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";