Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As pointed out by other people in the comments and answers, the design can be improved by making it object oriented.</p> <p>I think I understand the intention: first create a deck an shuffle it. After that, the first 5 elements of <code>deck</code> represent the hand of player 1. The next 5 elements represent the hand of player 2, and so on.</p> <p>While printing the hand of player 1, inside the loop, <code>selectionSort</code> is called. The method <code>selectionSort</code> sorts the complete <code>deck</code> array. A closer inspection of <code>selectionSort</code> shows me it does nothing! After fixing <code>selectionSort</code> you will see in the output is a random card followed by the last four cards of the last suit (clubs).</p> <p>I assume you attempt to sort the hand of player 1 by calling <code>selectionSort</code> within the loop that prints the hand of player 1.</p> <p>If my assumption is correct, you should modify <code>selectionSort</code> so that you can specify an lower and upper index that specifies which part of the array should be sorted. It could look like this:</p> <pre><code>public static void selectionSort(int[] deck, int start, int end) { for (int i = start; i&lt;end; i++) { int currentMax = deck[i]; int currentMaxIndex = i; for (int j = i + 1; j &lt; end; j++) { if (currentMax &lt; deck[j]) { currentMax = deck[j]; currentMaxIndex = j; } } if (currentMaxIndex != i) { deck[currentMaxIndex] = deck[i]; deck[i] = currentMax; } } } </code></pre> <p>To sort the cards for player 1, call <code>selectionSort(deck, 0, 5);</code>. For player 2 call <code>selectionSort(deck, 5, 10);</code>. For player 3 call <code>selectionSort(deck, 10, 15);</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload