Question: POINTERS HOMEWORK In the card-shuffling and dealing program of Fig. 5.34, we intentionally used an inefficient shuffling algonithm that introduced the possibility of indefinite postponement.

 POINTERS HOMEWORK In the card-shuffling and dealing program of Fig. 5.34,

POINTERS HOMEWORK In the card-shuffling and dealing program of Fig. 5.34, we intentionally used an inefficient shuffling algonithm that introduced the possibility of indefinite postponement. In this problem, you will create a high-performance shuffling algorithm that a voids indefinite postponement. Modify Fig. 5.24 as follows. Initialize the deck array as shown in Fig. 5.35. Modify the shuffle function to loop row by row and column by column through the array touching every element once. Each element should be swapped with a randomly selected element of the array. Print the resulting array to determine if the deck is satisfactorily shuffled (as in Fig. 5.36, for example). You may want your program to call the shuffle function several times to ensure a satisfactory shuffle. Note that although the approach in this problem improves the shuffling algorithm, the dealing algorithm still requires searching the deck array for card 1, then card 2, then card 3, and so on. Worse yet, even after the dealing algorithm locates and deals the card, the algorithm continues searching through the remainder of the deck. Modify the program of Fig. 5.24 so that once a card is dealt, no further attempts are made to match that card number, and the program immediately proceeds with dealing the next card. Unshused deck anay 0 23 4 6 7 8 9 10 1 1 0i 23 4 5 6 789 10 11 12 13 1 14 15 16 17 18 19 20 21 22 23 24 25 26 2 27 2 29 3031 32 33 34 35 36 37 38 39 3 40 41 42 43 44 45 46 47 48 49 50 51 52 Fig. 5.35 Unshuffled deck array Sample shutfled deck anay 0 2 3 4 56 789 10 1 12 0 19 40 27 25 36 46 10 34 35 41 18 113 28 14 16 21 30 11 31 17 24 7 1 2 12 33 15 42 43 23 45 3 29 3247 26 3 S0 38 52 39 4 519 s 37 4922 20

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!