Answered step by step
Verified Expert Solution
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 to N 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 josephusnm 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
main
Select Option from list.
Run All Tests
Test New Queue
Test Enqueue
Test Front
Test isEmpty
Test Dequeue
Run Randomized Tests
Josephus Puzzle
Enter Number of test to run:
Enter Number of People N:
Enter Person to Eliminate M:
Order Eliminated:
Josephus Test
main
Select Option from list.
Run All Tests
Test New Queue
Test Enqueue
Test Front
Test isEmpty
Test Dequeue
Run Randomized Tests
Josephus Puzzle
Enter Number of test to run:
Enter Number of People N:
Enter Person to Eliminate M:
Order Eliminated:
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 mth person to kill, m means kill every other person
void josephusint n int m;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started