Skip to content

Commit 869bfcf

Browse files
Merge pull request #3 from AdmAlexus/develop
Fix V3041, V3064 warnings from PVS-Studio Static Analyzer
2 parents 1d132bd + 9095f02 commit 869bfcf

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Advanced.Algorithms/DynamicProgramming/Maximizing/KnackSackProblems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static double KnackSack_Fractional(int W, int[] weights, int[] values)
6060
//O(n)
6161
for (int i = 0; i < weights.Length; i++)
6262
{
63-
ratios[i] = values[i] / weights[i];
63+
ratios[i] = (double)values[i] / weights[i];
6464
}
6565
//(o(nlog(n)
6666
//quick sort by desc weights

Advanced.Algorithms/Sorting/BucketSort.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ public static int[] Sort(int[] array, int bucketSize)
2828
int i;
2929
for (i = 0; i < array.Length; i++)
3030
{
31-
var bucketIndex = array[i] / bucketSize;
32-
33-
if(!buckets.ContainsKey(bucketIndex))
31+
if (bucketSize != 0)
3432
{
35-
buckets.Add(bucketIndex, new List<int>());
36-
}
33+
var bucketIndex = array[i] / bucketSize;
3734

38-
buckets[bucketIndex].Add(array[i]);
35+
if (!buckets.ContainsKey(bucketIndex))
36+
{
37+
buckets.Add(bucketIndex, new List<int>());
38+
}
39+
40+
buckets[bucketIndex].Add(array[i]);
41+
}
3942
}
4043

4144
i = 0;

0 commit comments

Comments
 (0)