Skip to content

Commit 9095f02

Browse files
committed
Fix V3064
1 parent 1aec43c commit 9095f02

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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)