Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Spring 2013 Engr.

Nahdia Majeed

Handout# 03 8th Jan, 2013

Sukkur Institute of Business Administration


Data Structures and Applications
You might have played the famous game of Musical Chairs, where at the end only one winner is left. Lets suppose I had a gift which I could give to one student only. I decided on the following procedure to determine which student would be given the gift. First, all of the students would be lined up one after the other and assigned numbers. The rst student would be number 1, the second number 2, and so on up to the last student, number n . Starting at the student in the rst position, I would then count three students down the line , and the third student would be eliminated from winning the gift and removed from the line. I would then continue, counting three more students, and eliminate every third student. When I reached the end of the line, I would continue counting from the beginning.

For example, if there were six students, the elimination process would proceed as follows: 123456 12456 1245 125 15 1 Initial list of students; start counting from 1. Student 3 eliminated; continue counting from 4. Student 6 eliminated; continue counting from 1. Student 4 eliminated; continue counting from 5. Student 2 eliminated; continue counting from 5. Student 5 eliminated; 1 is the lucky winner.

Write a program that creates a circular linked list of nodes to determine which position you should stand in to win if there are n students. Your program should simulate the elimination process by deleting the node that corresponds to the student that is eliminated for each step in the process.

You might also like