Skip to content

Commit 00b9db0

Browse files
committed
Changed the parameter name of arrayLength to items
1 parent 8a0b317 commit 00b9db0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Algorithms/Shufflers/RecursiveShuffler.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ public class RecursiveShuffler<T>
1212
{
1313
/// <summary>
1414
/// First, it will check the length of the array on the base case.
15-
/// Next, if there's still element left, it will shuffle the sub-array.
16-
/// Lastly, it will randomly select index from 0 to length of array then
17-
/// swap the elements array[arrayLength] and array[index].
15+
/// Next, if there's still items left, it will shuffle the sub-array.
16+
/// Lastly, it will randomly select index from 0 to number of items of the array
17+
/// then swap the elements array[items] and array[index].
1818
/// </summary>
1919
/// <param name="array">Array to shuffle.</param>
20-
/// <param name="arrayLength">The length of the array. Used for terminator.</param>
20+
/// <param name="items">Number of items in the array.</param>
2121
/// <param name="seed">Random generator seed. Used to repeat the shuffle.</param>
22-
public void Shuffle(T[] array, int arrayLength, int? seed = null)
22+
public void Shuffle(T[] array, int items, int? seed = null)
2323
{
24-
if(arrayLength <= 0)
24+
if(items <= 0)
2525
{
2626
return;
2727
}
2828

29-
Shuffle(array, arrayLength - 1, seed);
29+
Shuffle(array, items - 1, seed);
3030
var random = seed is null ? new Random() : new Random(seed.Value);
31-
int index = random.Next(arrayLength + 1);
32-
(array[arrayLength], array[index]) = (array[index], array[arrayLength]);
31+
int index = random.Next(items + 1);
32+
(array[items], array[index]) = (array[index], array[items]);
33+
(array[items], array[index]) = (array[index], array[items]);
3334
}
3435
}
3536
}

0 commit comments

Comments
 (0)