< previous page page_1155 next page >

Page 1155
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The soldiers arrange themselves in a circle and pull a name and a number from the helmets. Starting with the person whose name was pulled, they count off in a clockwise direction until they reach the number that was pulled. When the count stops, that soldier is eliminated from the circle. This continues until there is one soldier left, and that soldier rides for help.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Implement this process in C++. The names are stored in a file, and the last name in the file is followed by the word STOP. Use a circular linked list to represent the soldiers (a circular linked list is one in which the link member of the last node points back to the first node instead of containing NULL). Use recursive functions to count around the circle and eliminate the soldiers. Output the total number of soldiers in the group, the names of the soldiers who were eliminated, and the name of the soldier who will go for help.
Case Study Follow-Up
1. What is the base case in the recursive Convert function?
2. In the recursive Minimum function, what is the first array index to be evaluated? Explain.
3. Rewrite the Minimum function, assuming the list of integers is implemented as a dynamic linked list instead of an array.

 
< previous page page_1155 next page >