Question: So our class was asked to write code for the famous Josephus program and we did. In return, we were given this code and our
So our class was asked to write code for the famous Josephus program and we did. In return, we were given this code and our professor explained it, but I still don't understand it? It uses Queues. Can anyone please help explain what this code actually does with the queue in order to solve the Josephus problem? public class Josephus { public static void main(String[] args) { int m = Integer.parseInt(args[0]); int n = Integer.parseInt(args[1]); // initialize the queue Queue queue = new Queue(); for (int i = 0; i < n; i++) queue.enqueue(i); while (!queue.isEmpty()) { for (int i = 0; i < m-1; i++) queue.enqueue(queue.dequeue()); StdOut.print(queue.dequeue() + " "); } StdOut.println(); } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
