Purpose: To write a simple application involving a queue.

Problem: Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:

Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck.

Your task is to find the sequence of discarded cards and the last, remaining card.

Method: Use a linked list implementation of a queue with dummy head and tail nodes. Make sure your queue class has front and rear pointers and a size field for the number of non-dummy nodes.

Input: Input is from a file. Each line of input (except the last) contains a number n <= 50. The last line contains 0 and this line marks the end of input.

Sample input:

7
19
10
6
0

Output: All output goes to a file. For each number from the input produce two lines of output. The first line presents the sequence of discarded cards; the second line reports the last remaining hand. No line will have leading or trailing spaces.

Sample output:

Discarded cards: 1, 3, 5, 7, 4, 2
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining card: 4
Discarded cards: 1, 3, 5, 2, 6
Remaining card: 4
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.