Answered step by step
Verified Expert Solution
Link Copied!

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 1 for True and 0 for false
*/
char isEmpty(Queue *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 enqueue(int 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 -1 if the queue is empty
*/
int front(Queue *Q);
/**
Remove the first value from the queue
@param Q is the queue to remove from
*/
void dequeue(Queue *Q);
/**
Print the Queue to STD out. Used for debugging.
@param Q is the queue to print
*/
void printQueue(Queue *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 m-th person to kill, m=2 means kill every other person
*/
void josephus(int 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 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.
josephus(n,m)inqueue.c.
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 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

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

Step: 3

blur-text-image

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago