Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please write a c++ code to solve the Josephus Problem with a number of people(n), a number to be skip(k), and please don't use any

Please write a c++ code to solve the Josephus Problem with a number of people(n), a number to be skip(k), and please don't use any defined class about linked list. Thank you!

image text in transcribed

(a) The program pops a message: Please input n: . Then the program reads n from the keyboard input.

(b) The program pops the second message: Please input k: . The program reads k from the keyboard input.

(c) The program must use the struct node defined in note3 to construct the linked list for items 1 to n (not 0 to n-1). 1 to n are saved as info in each node in the linked list.

(d) Implement the Josephus problem

(e) Output the last node left, e.g. The last node is 5.

(f) In this problem, you cannot use any previously defined class about linked list. Use similar operations on pages 11 to 16 of note3

People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed. The problem - given the number of people (n), starting point, direction, and number to be skipped (k) - is to choose the position in the initial circle to avoid execution (i.e. guessing who is the survivor)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions