Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the following is the functions plase only use queues A structure / * * to represent a single node in a one directional linked list.
the following is the functions plase only use queues
A structure
to represent a single node in a one directional linked list.
struct Node
int value; The value stored at this node.
struct Node next; A pointer to the next node in the list.
;
Give the struct a short name
typedef struct Node Node;
A structure to represent a classic Queue.
struct Queue
Node head; Pointer to the first value in queue.
Node tail; Pointer to last value in the queue.
;
Give the Queue a short name
typedef struct Queue Queue;
Create a new empty queue.
@return A pointer to the new queue struct
Queue newQueue;
Determine if the queue is empty
@param Q is the queue to check
@return for True and for false
char isEmptyQueue Q;
Add a new value to the end of the queue
@param v is the value to add
@param Q is the Q to add the value to
void enqueueint v Queue Q;
Determine the value at the front of the queue
@param Q is the queue to look at
@return The first value in the queue or if the queue is empty
int frontQueue Q;
Remove the first value from the queue
@param Q is the queue to remove from
void dequeueQueue Q;
Print the Queue to STD out. Used for debugging.
@param Q is the queue to print
void printQueueQueue Q;
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;
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.
josephusnminqueuec
YouMUSTuse your Queue to solve this problem. If you use any arrays in any part of this solution, your code will be rejected.
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:
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