(int[] cards, int i)
| 10 | } |
| 11 | |
| 12 | public static int[] shuffleArrayRecursively(int[] cards, int i) { |
| 13 | if (i == 0) { |
| 14 | return cards; |
| 15 | } |
| 16 | |
| 17 | /* shuffle elements 0 through index - 1 */ |
| 18 | shuffleArrayRecursively(cards, i - 1); |
| 19 | int k = rand(0, i); |
| 20 | |
| 21 | /* Swap element k and index */ |
| 22 | int temp = cards[k]; |
| 23 | cards[k] = cards[i]; |
| 24 | cards[i] = temp; |
| 25 | |
| 26 | /* Return shuffled array */ |
| 27 | return cards; |
| 28 | } |
| 29 | |
| 30 | public static void shuffleArrayInteratively(int[] cards) { |
| 31 | for (int i = 0; i < cards.length; i++) { |