Question: The problem is known as the Josephus problem and postulates a group of people of size N are standing in a circle waiting to be

 The problem is known as the Josephus problem and postulates a
group of people of size N are standing in a circle waiting

The problem is known as the Josephus problem and postulates a group of people of size N are standing in a circle waiting to be eliminated. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of M people are skipped, the next person is eliminated. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains. For example, suppose that M = 3 and there are N = 5 people named A, B, C, D and E. We count three people starting at A, so that C is eliminated first. We then begin at D and count D, E and back to A, so that A is eliminated next. Then we count B, D and E, and finally B, D and B, so that D is the one who remains last. For this computer assignment, you are to write and implement a C++ program to simulate and solve the Josephus problem. The input to the program is the number M and a list of N names, which is clockwise ordering of the circle, beginning with the person from whom the count is to start. After each removal, the program should print the names of all people in the circle until only one person remains. However, to save the printing space, print the names of the remaining people only after K elimination, where K 2 1 is also an input argument to the program. The input arguments N, M and K can be entered from the stdin in the given order 1. Name the people in the circle in the following sequence: A1, A2 A9, B1, B2 N and M when the program prompts for them and use a list container 2. In addition to the main ) routine, implement the following subroutines in your . void init vals (list& L, args& in ): This routine reads the prompts for them and prints out those values on stdout. You can find B9, C1, C2., and start counting from the person A1. Enter the input values to store the names of N people. program input values N, M and K of the struct args in when the program the definition of the struct args in the header file prog5.h, which is defined as struct args funsigned N, M, K; ; The routine prints out those values on stdout, and fills the names of people in the list L void print list ( const list & L, con t unsigned& cnt) This routine prints out the contents of the list L at the beginning and after removing K names (each time) from the list, until only one name remains in the list, where cnt has an initial value 0 and it indicates the total

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!