From 0356a9cdf30b0f3ecdf5632e73e9f8a00a924253 Mon Sep 17 00:00:00 2001 From: Panquesito7 Date: Tue, 23 Jun 2020 14:35:13 -0500 Subject: [PATCH] fix: Various LGTM fixes --- data_structures/binary_search_tree.cpp | 12 ++++++------ math/realtime_stats.cpp | 2 +- sorting/bead_sort.cpp | 2 +- sorting/comb_sort.cpp | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data_structures/binary_search_tree.cpp b/data_structures/binary_search_tree.cpp index 3cc7d09fb..86057c6c5 100644 --- a/data_structures/binary_search_tree.cpp +++ b/data_structures/binary_search_tree.cpp @@ -14,17 +14,17 @@ struct node { node *right; }; -struct queue { +struct Queue { node *t[100]; int front; int rear; }; -queue q; +Queue queue; -void enqueue(node *n) { q.t[q.rear++] = n; } +void enqueue(node *n) { queue.t[queue.rear++] = n; } -node *dequeue() { return (q.t[q.front++]); } +node *dequeue() { return (queue.t[queue.front++]); } void Insert(node *n, int x) { if (x < n->val) { @@ -123,8 +123,8 @@ void Post(node *n) { } int main() { - q.front = 0; - q.rear = 0; + queue.front = 0; + queue.rear = 0; int value; int ch; node *root = new node; diff --git a/math/realtime_stats.cpp b/math/realtime_stats.cpp index 5f353ac4d..672acfa03 100644 --- a/math/realtime_stats.cpp +++ b/math/realtime_stats.cpp @@ -35,7 +35,7 @@ class stats_computer1 { n++; T tmp = x - K; Ex += tmp; - Ex2 += tmp * tmp; + Ex2 += static_cast(tmp) * tmp; } /** return sample mean computed till last sample */ diff --git a/sorting/bead_sort.cpp b/sorting/bead_sort.cpp index f3276bfcd..4745987d9 100644 --- a/sorting/bead_sort.cpp +++ b/sorting/bead_sort.cpp @@ -14,7 +14,7 @@ void beadSort(int *a, int len) { // allocating memory unsigned char *beads = new unsigned char[max * len]; - memset(beads, 0, max * len); + memset(beads, 0, static_cast(max) * len); // mark the beads for (int i = 0; i < len; i++) diff --git a/sorting/comb_sort.cpp b/sorting/comb_sort.cpp index 1b0a4d706..ab0b456dd 100644 --- a/sorting/comb_sort.cpp +++ b/sorting/comb_sort.cpp @@ -14,7 +14,7 @@ int FindNextGap(int x) { return std::max(1, x); } -void CombSort(int a[], int l, int r) { +void CombSort(int b[], int l, int r) { // Init gap int gap = n; @@ -30,8 +30,8 @@ void CombSort(int a[], int l, int r) { // Compare all elements with current gap for (int i = l; i <= r - gap; ++i) { - if (a[i] > a[i + gap]) { - std::swap(a[i], a[i + gap]); + if (b[i] > b[i + gap]) { + std::swap(b[i], b[i + gap]); swapped = true; } }