Use a circular list to implement thenbspjosephus problem


Problem:

Use a circular list to implement the Josephus Problem.  In the Josephus Problem, there is originally a circle of people numbered from one to n.  Some number is chosen as the starting person, and an interval of size m is selected.  Then, starting at the chosen person, every mth person is eliminated until only one person remains.  The output should be a list of the eliminated people in the order of elimination, and a statement of which person remains.  Do this once with the circular list class implemented with nodes and pointers and once as a circular array with some method of designating a person as "not there."  The two implementations of the circular list should be designed to require no change to the code outside the circular list class.  Both circular list classes should have functions AdvanceN(n) and DeleteThis(x), where AdvanceN(n) returns a new position in the list that is n places further on, and DeleteThis(x) deletes person x and returns the position previous to x.

  • Solve without using a Template
  • There are two parts to this question - Do this once with the circular list class implemented with nodes and pointers and once as a circular array (do not use pointers here.  Integers will work fine) with some method of designating a person as "not there."
  • The program should allow the user to cin >>startingPerson and cin>>intervalSize
  • The class(es) should be declared in a separate .h file(s).

Additional Information:

This question is from Computer Science and it explains about writing program in C++ which implements Josephus problem. Josephus problem is the classical problem on counting out people. This problem has been implemented and solved using C++ program.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Use a circular list to implement thenbspjosephus problem
Reference No:- TGS01109710

Now Priced at $40 (50% Discount)

Recommended (98%)

Rated (4.3/5)