Arrays/Java/Repeatedly Remove
From charlesreid1
Question from Goodrich et al, Data Structures in Java, Chapter 3: Arrays and Lists
Question 3.2: Write a Java method that repeatedly selects and removes a random entry from an array until the array holds no more entries.
We can first create an array of sequential integer indices, then we can utilize the Fisher Yates method to shuffle this array of indexes.
For example, to shuffle an array holding integers [5, 44, 89]:
First, generate an array of sequential integer indices: [0, 1, 2]
Now, use the Fisher Yates method to shuffle these: [2, 1, 0]
Last, remove the items from the original array in the order [2, 1, 0]. (Remove them by setting to null or 0.)