From 48b7773b37fe13792eed229e12aa54bec7d1ce5a Mon Sep 17 00:00:00 2001 From: Panquesito7 Date: Tue, 23 Jun 2020 16:34:53 -0500 Subject: [PATCH] fix: Various LGTM fixes --- data_structures/stack_using_array.cpp | 14 +++++++------- data_structures/stack_using_linked_list.cpp | 14 +++++++------- math/fibonacci_fast.cpp | 12 ++++++------ others/paranthesis_matching.cpp | 10 +++++----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/data_structures/stack_using_array.cpp b/data_structures/stack_using_array.cpp index 36be9eb39..ab2d7d7dd 100644 --- a/data_structures/stack_using_array.cpp +++ b/data_structures/stack_using_array.cpp @@ -1,31 +1,31 @@ #include 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; diff --git a/data_structures/stack_using_linked_list.cpp b/data_structures/stack_using_linked_list.cpp index ae53fe95a..05f0d3d6a 100644 --- a/data_structures/stack_using_linked_list.cpp +++ b/data_structures/stack_using_linked_list.cpp @@ -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; diff --git a/math/fibonacci_fast.cpp b/math/fibonacci_fast.cpp index 8fdb20058..80e9108ea 100644 --- a/math/fibonacci_fast.cpp +++ b/math/fibonacci_fast.cpp @@ -24,23 +24,23 @@ const uint64_t MAX = 93; /** Array of computed fibonacci numbers */ -uint64_t f[MAX] = {0}; +uint64_t numbers[MAX] = {0}; /** Algorithm */ uint64_t fib(uint64_t n) { if (n == 0) return 0; if (n == 1 || n == 2) - return (f[n] = 1); + return (numbers[n] = 1); - if (f[n]) - return f[n]; + if (numbers[n]) + return numbers[n]; uint64_t k = (n % 2 != 0) ? (n + 1) / 2 : n / 2; - f[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) + numbers[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) : (2 * fib(k - 1) + fib(k)) * fib(k); - return f[n]; + return numbers[n]; } /** Main function */ diff --git a/others/paranthesis_matching.cpp b/others/paranthesis_matching.cpp index 2a6358d94..0a1a9e474 100644 --- a/others/paranthesis_matching.cpp +++ b/others/paranthesis_matching.cpp @@ -20,13 +20,13 @@ char stack[MAX]; //! pointer to track stack index -int top = -1; +int top_var = -1; //! push byte to stack variable -void push(char ch) { stack[++top] = ch; } +void push(char ch) { stack[++top_var] = ch; } //! pop a byte out of stack variable -char pop() { return stack[top--]; } +char pop() { return stack[top_var--]; } //! @}-------------- 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 >= 0 && stack[top] == opening(exp[i])) { + } else if (top_var >= 0 && stack[top_var] == 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 == -1) { + if (valid == 1 && top_var == -1) { std::cout << "\nCorrect Expression"; } else { std::cout << "\nWrong Expression";