We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1aec43c commit 9095f02Copy full SHA for 9095f02
Advanced.Algorithms/Sorting/BucketSort.cs
@@ -28,14 +28,17 @@ public static int[] Sort(int[] array, int bucketSize)
28
int i;
29
for (i = 0; i < array.Length; i++)
30
{
31
- var bucketIndex = array[i] / bucketSize;
32
-
33
- if(!buckets.ContainsKey(bucketIndex))
+ if (bucketSize != 0)
34
35
- buckets.Add(bucketIndex, new List<int>());
36
- }
+ var bucketIndex = array[i] / bucketSize;
37
38
- buckets[bucketIndex].Add(array[i]);
+ if (!buckets.ContainsKey(bucketIndex))
+ {
+ buckets.Add(bucketIndex, new List<int>());
+ }
39
+
40
+ buckets[bucketIndex].Add(array[i]);
41
42
}
43
44
i = 0;
0 commit comments