Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the great city of Atlantis, Prince Val had many sultors. He decided on the following algorithm to determine which person he would marry.

  

In the great city of Atlantis, Prince Val had many sultors. He decided on the following algorithm to determine which person he would marry. First, the suitors would be lined up in order and assigned a number starting with 1. the second would be 2, and so on up to n sultors. Starting with the first, he would count down the line with each letter of his name "V", "a", "I", and then the suitor at "I" would be eliminated from the line. Val would continue counting three more suitors, and eliminating every third one. When Val reached the end of the line, he would resume counting at the beginning of the line. For example, if there were seven suitors, the elimination process would be as follows: Initial list of suitors; Start counting from 1. Suitor #3 eliminated; Suitor #6 eliminated; Suitor #2 eliminated; Suitor #7 eliminated; Suitor #S eliminated; Continue counting at 4. Continue counting at 7. Continue counting at 4. Continue counting at 1. Continue counting at 1. Finally, #1 is eliminated, and suitor #4 is selected. 1234567 124567 12457 1457 145 14 4 Write a program that implements a linked list of nodes to determine the position a suitor should stand if they want to marry the prince, when there are n suitors. Your program should eliminate the suitor by deleting the node corresponding to the suitor for each step of the process. Each sultor also has a name. You should either add the name, a string, as part of the node object or use a parallel HashMap to perform a name lookup. Your program should prompt the user for the number of suitors, each suitor's name, and then after your algorithm runs, print the selected suitor and their name. Be sure to use prompts that make sense to a user who has never run your program before.

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

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions