MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / fillGrid

Method fillGrid

src/main/java/com/thealgorithms/sorts/BeadSort.java:26–39  ·  view source on GitHub ↗
(final int[] array)

Source from the content-addressed store, hash-verified

24 }
25
26 private BeadState[][] fillGrid(final int[] array) {
27 final var maxValue = Arrays.stream(array).max().orElse(0);
28 var grid = getEmptyGrid(array.length, maxValue);
29
30 int[] count = new int[maxValue];
31 for (int i = 0, arrayLength = array.length; i < arrayLength; i++) {
32 int k = 0;
33 for (int j = 0; j < array[i]; j++) {
34 grid[count[maxValue - k - 1]++][k] = BeadState.BEAD;
35 k++;
36 }
37 }
38 return grid;
39 }
40
41 private BeadState[][] getEmptyGrid(final int arrayLength, final int maxValue) {
42 BeadState[][] grid = new BeadState[arrayLength][maxValue];

Callers 1

sortMethod · 0.95

Calls 3

getEmptyGridMethod · 0.95
streamMethod · 0.80
maxMethod · 0.45

Tested by

no test coverage detected