mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-14 02:30:40 +08:00
fix: Various LGTM fixes
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
int *stack;
|
||||
int top = 0, stack_size;
|
||||
int top_var = 0, stack_size;
|
||||
|
||||
void push(int x) {
|
||||
if (top == stack_size) {
|
||||
if (top_var == stack_size) {
|
||||
std::cout << "\nOverflow";
|
||||
} else {
|
||||
stack[top++] = x;
|
||||
stack[top_var++] = x;
|
||||
}
|
||||
}
|
||||
|
||||
void pop() {
|
||||
if (top == 0) {
|
||||
if (top_var == 0) {
|
||||
std::cout << "\nUnderflow";
|
||||
} else {
|
||||
std::cout << "\n" << stack[--top] << " deleted";
|
||||
std::cout << "\n" << stack[--top_var] << " deleted";
|
||||
}
|
||||
}
|
||||
|
||||
void show() {
|
||||
for (int i = 0; i < top; i++) {
|
||||
for (int i = 0; i < top_var; i++) {
|
||||
std::cout << stack[i] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void topmost() { std::cout << "\nTopmost element: " << stack[top - 1]; }
|
||||
void topmost() { std::cout << "\nTopmost element: " << stack[top_var - 1]; }
|
||||
int main() {
|
||||
std::cout << "\nEnter stack_size of stack : ";
|
||||
std::cin >> stack_size;
|
||||
|
||||
@@ -6,28 +6,28 @@ struct node {
|
||||
node *next;
|
||||
};
|
||||
|
||||
node *top;
|
||||
node *top_var;
|
||||
|
||||
void push(int x) {
|
||||
node *n = new node;
|
||||
n->val = x;
|
||||
n->next = top;
|
||||
top = n;
|
||||
n->next = top_var;
|
||||
top_var = n;
|
||||
}
|
||||
|
||||
void pop() {
|
||||
if (top == NULL) {
|
||||
if (top_var == NULL) {
|
||||
cout << "\nUnderflow";
|
||||
} else {
|
||||
node *t = top;
|
||||
node *t = top_var;
|
||||
cout << "\n" << t->val << " deleted";
|
||||
top = top->next;
|
||||
top_var = top_var->next;
|
||||
delete t;
|
||||
}
|
||||
}
|
||||
|
||||
void show() {
|
||||
node *t = top;
|
||||
node *t = top_var;
|
||||
while (t != NULL) {
|
||||
cout << t->val << "\n";
|
||||
t = t->next;
|
||||
|
||||
Reference in New Issue
Block a user