File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
src/main/java/by/andd3dfx/sorting Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 6
6
/**
7
7
* We have a very long array of people ages.
8
8
* Need to count number of people for each age.
9
+ *
10
+ * @see <a href="https://youtu.be/vFsDPm7ecsM">Video solution</a>
9
11
*/
10
12
public class ArrayOfAges {
11
13
Original file line number Diff line number Diff line change 3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
5
6
- /**
7
- * @see <a href="https://www.youtube.com/watch?v=vFsDPm7ecsM">Video solution</a>
8
- */
9
6
public class BucketSort {
10
7
11
8
private static final int BUCKETS_COUNT = 10 ;
@@ -19,7 +16,8 @@ public static <T extends Comparable> void apply(T[] items) {
19
16
20
17
// Fill in buckets
21
18
for (int i = 0 ; i < items .length ; i ++) {
22
- buckets .get (determineBucketIndex (items [i ], BUCKETS_COUNT )).add (items [i ]);
19
+ var bucketIndex = determineBucketIndex (items [i ], BUCKETS_COUNT );
20
+ buckets .get (bucketIndex ).add (items [i ]);
23
21
}
24
22
25
23
int currIndex = 0 ;
@@ -30,7 +28,7 @@ public static <T extends Comparable> void apply(T[] items) {
30
28
Comparable [] array = bucket .toArray (new Comparable [0 ]);
31
29
InsertionSort .apply (array );
32
30
33
- // Populate result array with values from bucket
31
+ // Populate the result array with values from bucket
34
32
for (var item : array ) {
35
33
items [currIndex ] = (T ) item ;
36
34
currIndex ++;
You can’t perform that action at this time.
0 commit comments