Bad News Bearers Introduction There is some bad news to be delivered, and X has taken on the dangerous mission. Nobody really wants to be the one to take the news; the way goes through enemy territory and, even if the messenger gets through, the classic fate of the bearer of bad news may be waiting. (Let's just say, this is how the phrase "Don't shoot the messenger" became relevant.) To determine which messenger will be sent, X sits all of his messengers down in a circle, selects a number, and starts to count off. Messengers are allowed to leave the circle one by one, and the last messenger left is the one who will deliver the bad news. The counting off procedure is slightly unusual, however, because it is actually the messenger after the last one counted who gets to leave the circle. Consider the following example with 5 messengers, in which the number selected for counting off is 7. We'll start at the "head" of the list and move forward. Since it is circular, the "head" simply refers to whatever the current element in the list is. We count off 7 messengers: Alice, autumn, Brad, Jon, Zach, Alice, and Autumn. Since autumn was the last one to count off, Brad (who would be next in the list) is declared "safe" and removed from the circle. We then count off 7 messengers again, starting with Jon (the next person in the list, since Brad was removed). The seven are Jon, Zach, Alice, Autumn, Jon, Zach, and Alice. Since Autumn is the next one in the list, she is declared safe and removed. Autumn was removed, so we now begin with Jon and count off as before. This time Zach is removed. We begin the counting with Alice, and Jon is removed. Since Alice is the last one left, she will be the messenger to take the bad news. Your mission: Implement a linked list in c++. The main function should implement the algorithm to choose the bearer of bad news. You should prompt the user for the "skip value," the number of messengers to skip before removing one from the list, and you should report to the user who the bad news bearer will be
Bad News Bearers
Introduction
There is some bad news to be delivered, and X has taken on the dangerous mission. Nobody really wants to be the one to take the news; the way goes through enemy territory and, even if the messenger gets through, the classic fate of the bearer of bad news may be waiting. (Let's just say, this is how the phrase "Don't shoot the messenger" became relevant.)
To determine which messenger will be sent, X sits all of his messengers down in a circle, selects a number, and starts to count off. Messengers are allowed to leave the circle one by one, and the last messenger left is the one who will deliver the bad news. The counting off procedure is slightly unusual, however, because it is actually the messenger after the last one counted who gets to leave the circle. Consider the following example with 5 messengers, in which the number selected for counting off is 7.
We'll start at the "head" of the list and move forward. Since it is circular, the "head" simply refers to whatever the current element in the list is. We count off 7 messengers: Alice, autumn, Brad, Jon, Zach, Alice, and Autumn. Since autumn was the last one to count off, Brad (who would be next in the list) is declared "safe" and removed from the circle. We then count off 7 messengers again, starting with Jon (the next person in the list, since Brad was removed). The seven are Jon, Zach, Alice, Autumn, Jon, Zach, and Alice. Since Autumn is the next one in the list, she is declared safe and removed. Autumn was removed, so we now begin with Jon and count off as before. This time Zach is removed. We begin the counting with Alice, and Jon is removed. Since Alice is the last one left, she will be the messenger to take the bad news.
Your mission:
Implement a linked list in c++.
The main function should implement the
Step by step
Solved in 3 steps with 1 images