Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please solve this using quesues only in C language ! In the Josephus problem from antiquity, N people are in dire straits and agree to

please solve this using quesues only in C language !
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.
Learn more about the problem here: The Josephus Problem - Numberphile.
Implement the function josephus(n,m) in queue.c.
You MUST use your Queue to solve this problem. If you use any arrays in any part of this solution, your code will be rejected.
The function takes two integers as input. The integers are n and m. Your program will print the people in the order in which they are eliminated.
Josephus will sit in whatever value is printed last. You must use your Queue from the previous part to solve this problem.
Additional Notes
You may assume the user will always give two positive numbers.
You may assume the user will always enter values such that n > m.
Print a newline instead of a space after the last person
Joesphus Test 01
%./main
Select Option from list.
0.) Run All Tests
1.) Test New Queue
2.) Test Enqueue
3.) Test Front
4.) Test isEmpty
5.) Test Dequeue
6.) Run Randomized Tests
7.) Josephus Puzzle
Enter Number of test to run:
7
Enter Number of People (N):
7
Enter Person to Eliminate (M):
2
Order Eliminated:
1350426
Josephus Test 02
%./main
Select Option from list.
0.) Run All Tests
1.) Test New Queue
2.) Test Enqueue
3.) Test Front
4.) Test isEmpty
5.) Test Dequeue
6.) Run Randomized Tests
7.) Josephus Puzzle
Enter Number of test to run:
7
Enter Number of People (N):
7
Enter Person to Eliminate (M):
3
Order Eliminated:
2516403
/**
Solve the Josephus Puzzle Using a Queue. Print out the people in the order
killed. Josephus sits in the last position printed.
@param n is the number of people
@param m is the m-th person to kill, m=2 means kill every other person
*/
void josephus(int n, int m);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago