CSE101 C++ Introduction to Data Structures and Algorithms
作者:花生_TL007 | 2024-03-23 08:33:50
赞
踩
CSE101 C++ Introduction to Data Structures and Algorithms
CSE 101
Introduction to Data Structures and Algorithms
Programming Assignment 5
In this project you will create a new, and somewhat different integer List ADT, this time in C++. You will use this List to perform shuffling operations, and determine how many shuffles are necessary to bring a List back into its original order. Begin by carefully reviewing Queue and Stack examples posted on the webpage in Examples/C++. These examples establish our norms and conventions for building ADTs in the C++ language. Also read the handout ADTs in C++. The header file List.h has also been posted at
Examples/pa5, along with a test client, some output files and a Makefile for this project.
The Perfect Shuffle
A perfect shuffle (also called a riffle shuffle) is one in which a deck of cards is split evenly, then merged into a new deck by alternately inserting cards from each half into the new deck. For instance, if our deck contains 7 cards, labeled 0-6, we would perform the following steps.
Deck: 0 1 2 3 4 5 6
Split: 0 1 2 | 3 4 5 6
Prepare to Merge: 3 4 5 6
0 1 2
Merge: 3 0 4 1 5 2 6
Performing the same perfect shuffle operation on the new list, we get: 1 3 5 0 2 4 6. Repeating the shuffle once again gives the original order: 0 1 2 3 4 5 6. We say that the order of this re-arrangement (or permutation) is 3, since applying it to any deck 3 times returns the deck to its original order.