n an ancient land, the beautiful princess Eve (or handsome prince Val) had many suitors. Being royalty, it was decided that a special process must be used to determine which suitor would win the hand of the prince/princess. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at 4 the suitor in the first position, she/he would then count three suitors down the line (because of the three letters in his/her name) and that suitor would be eliminated and removed from the line. The prince/princess would then continue, counting three more suitors, and eliminate every third suitor. When the end of the line is reached, counting would continue from the beginning. For example, if there were 6 suitors, the elimination process would proceed as follows: 123456            initial list of suitors, starting count from 1 12456              suitor 3 eliminated, continue counting from 4 1245                 suitor 6 eliminated, continue counting from 1 125                    suitor 4 eliminated, continue counting from 5 15                       suitor 2 eliminated, continue counting from 5 1                          suitor 5 eliminated, 1 is the lucky winner A Solution Using Queues Write a program/method called findPlaceToStand (int n) that uses a queue to determine the positions that you should stand in to marry the prince/princess if there are n suitors. When counting, traverse the queue. For the first and second suitors (numbers) on the queue, put them at the back of the queue. For the third suitor, discard the number. When there is only one number left, the suitor is determined. In the driver, find the commented out code near the bottom of main() to get started. The last two lines invoke the function findPlaceToStand() This takes an integer and determines where to stand to win in the game of love. Should you use a List, a Stack, or a Queue to solve this? Does the selection of structure affect your results? Use the Queue interface, but allocate each queue as a LinkedList or use your own Linked List implementation, if finished: Queue myQueue = new LinkedList(); Both Queue and LinkedList are defined in java.util.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

n an ancient land, the beautiful princess Eve (or handsome prince Val) had many suitors. Being royalty, it was decided that a special process must be used to determine which suitor would win the hand of the prince/princess. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at 4 the suitor in the first position, she/he would then count three suitors down the line (because of the three letters in his/her name) and that suitor would be eliminated and removed from the line. The prince/princess would then continue, counting three more suitors, and eliminate every third suitor. When the end of the line is reached, counting would continue from the beginning.

For example, if there were 6 suitors, the elimination process would proceed as follows:

123456            initial list of suitors, starting count from 1

12456              suitor 3 eliminated, continue counting from 4

1245                 suitor 6 eliminated, continue counting from 1

125                    suitor 4 eliminated, continue counting from 5

15                       suitor 2 eliminated, continue counting from 5

1                          suitor 5 eliminated, 1 is the lucky winner

A Solution Using Queues

Write a program/method called findPlaceToStand (int n) that uses a queue to determine the positions that you should stand in to marry the prince/princess if there are n suitors. When counting, traverse the queue. For the first and second suitors (numbers) on the queue, put them at the back of the queue. For the third suitor, discard the number. When there is only one number left, the suitor is determined.

  • In the driver, find the commented out code near the bottom of main() to get started.
  • The last two lines invoke the function findPlaceToStand()
    • This takes an integer and determines where to stand to win in the game of love.
      • Should you use a List, a Stack, or a Queue to solve this?
        • Does the selection of structure affect your results?

Use the Queue interface, but allocate each queue as a LinkedList or use your own Linked List implementation, if finished:

Queue<Integer> myQueue = new LinkedList<Integer>();

Both Queue and LinkedList are defined in java.util.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education