MCPcopy Create free account
hub / github.com/careercup/ctci / shuffleArrayRecursively

Method shuffleArrayRecursively

java/Chapter 18/Question18_2/Question.java:12–28  ·  view source on GitHub ↗
(int[] cards, int i)

Source from the content-addressed store, hash-verified

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++) {

Callers

nothing calls this directly

Calls 1

randMethod · 0.95

Tested by

no test coverage detected