Riffle Shuffle

Goal

  1. Implement the Riffle Shuffle as a function, whose input is an array (the length may be shorter than 52) of integers.
  2. You may define it as
    void riffle_shuffule(int card[], int n)
    where n is the size of the array.
    The function will shuffle the sequence of array elements according to Riffle Shuffle.
  3. You may learn how to do riffle shuffle from these video clips:
    1. The Riffle Shuffle for Playing Card Shuffling
    2. The Riffle Shuffle
    3. Slow Motion of Riffle Shuffle
  4. If the input array is { 1, 2, 3, 4, 5, 6, 7, 8 }, after the riffle shuffle, it becomes { 5, 1, 6, 2, 7, 3, 8, 4}.
  5. If the input array is { 1, 2, 3, 4, 5, 6, 7 }, after the riffle shuffle, it becomes { 4, 1, 5, 2, 6, 3, 7}. (The last element is not changed.)
  6. The main function may look like this:
        int main()
        {
    	int card[MAX];		
    	initialize(card, MAX);
    	print_cards(card, MAX);
    	riffle_shuffle(card, MAX);
    	print_cards(card, MAX);
    	return 0;
        }
        
  7. Q: If you repeatedly riffle shuffle the deck of cards for 51 times, what will be the result?
  8. Q: If you repeatedly shuffle the deck of cards for 52 times, what will be the result?