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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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. 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
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education