Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In an ancient land, the beautiful princess Eve had many suitors. She decided on
- the following procedure to determine which suitor she would marry. 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 the first suitor, she would then count three suitors down the line
- (because of the three letters in her name) and the third suitor would be eliminated
- from winning her hand and removed from the line. Eve would then continue, counting
- three more suitors, and eliminating every third suitor. When she reached the end
- of the line, she would reverse direction and work her way back to the beginning.
- Similarly, on reaching the first person in line, she would reverse direction and make
- her way to the end of the line. For example, if there were five suitors, then the
- elimination process would proceed as follows:
- 12345 Initial list of suitors; start counting from 1.
- 1245 Suitor 3 eliminated; continue counting from 4 and bounce from end
- back to
- Suitor 4 eliminated; continue counting back from 2 and bounce from
- front back to 2.
- 15
- Suitor 2 eliminated; continue counting forward from 5.
- 1
- Suitor 5 eliminated; 1 is the lucky winner.
- Write a program that uses an ArrayList or Vector to determine which position you
- should stand in to marry the princess if there are n suitors. Your program should
- use the ListIterator interface to traverse the list of suitors and remove a suitor. Be
- careful that your iterator references the proper object upon reversing direction at
- the beginning or end of the list. The suitor at the beginning or end of the list should
- only be counted once when the princess reverses the count.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement