Skip to content

Fix V3041, V3064 warnings from PVS-Studio Static Analyzer #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static double KnackSack_Fractional(int W, int[] weights, int[] values)
//O(n)
for (int i = 0; i < weights.Length; i++)
{
ratios[i] = values[i] / weights[i];
ratios[i] = (double)values[i] / weights[i];
}
//(o(nlog(n)
//quick sort by desc weights
Expand Down
15 changes: 9 additions & 6 deletions Advanced.Algorithms/Sorting/BucketSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ public static int[] Sort(int[] array, int bucketSize)
int i;
for (i = 0; i < array.Length; i++)
{
var bucketIndex = array[i] / bucketSize;

if(!buckets.ContainsKey(bucketIndex))
if (bucketSize != 0)
{
buckets.Add(bucketIndex, new List<int>());
}
var bucketIndex = array[i] / bucketSize;

buckets[bucketIndex].Add(array[i]);
if (!buckets.ContainsKey(bucketIndex))
{
buckets.Add(bucketIndex, new List<int>());
}

buckets[bucketIndex].Add(array[i]);
}
}

i = 0;
Expand Down