mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
docs: Change variable names
This commit is contained in:
parent
f05aadf3b8
commit
b6fdaa63eb
@ -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;
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user