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 *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;
|
||||||
|
@ -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";
|
||||||
|
Loading…
Reference in New Issue
Block a user