Question: complete the missing code where it says //Your Code 1 Problem 2: Josephus class (35) Description: In the Josephus problem from antiquity, N people are

1 Problem 2: Josephus class (35) Description: In the Josephus problem from antiquity, N people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to N - 1) and proceed around the circle, eliminating every Mth person until only one person is left. Legend has it that Josephus figured out where to sit to avoid being eliminated. Finish the Queue client Josephus.java that takes N and M from keyboard and prints out the order in which people are eliminated (and thus would show Josephus where to sit in the circle). Hint: you can make the Queue a virtual circle, so that every time, you can dequeue the first M-1 person, and enqueue them back to the end of the Queue, and therefore the Mth person will be the most front one on the Queue to dequeue out. Outputs: Your outputs should look something as follows. $ java Josephus Please enter a number for N indicating the total number of people: 7 Please enter a number M indicating the Mth person to be eliminated: 2 People will be eliminated in such a sequence: 1 3 5 0 4 2 6 package hw3; import java.util. public class Josephus { public ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
