From charlesreid1

Revision as of 21:53, 5 June 2017 by Admin (talk | contribs) (Created page with "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 a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.)