Circular Linked List ( Due 22 Mar 2013 )

The problem that you are going to solve is known as Josephus problem and it is stated as follows. There is a group of soldiers surrounded by an overwhelming enemy force. There is no hope for victory without reinforcements, so they make a pact to commit suicide.

They form a circle and a number n is picked from a hat. One of their names is also picked from a hat. Beginning with the soldier whose name is picked, they begin to count clockwise around the circle. When the count reaches n, that soldier is executed, and the count begins again with the next man. The process continues so that each time the count reaches n, a man is removed from the circle. Once a soldier is removed from the circle he is no longer counted. The last soldier remaining was supposed to take his own life. According to legend the last soldier remaining was Josephus and instead of taking his own life he joined the enemy forces and survived.

The problem is: given a number n, the ordering of the men in the circle, and the man from whom the count begins, to determine the order in which the men are eliminated from the circle and which man escapes. For example, suppose that n equals 3 and there are five men named A, B, C, D, and E. We count three men, starting at A, so that C is eliminated first. We then begin at D and count D, E, and back to A, so that A is eliminated next. Then we count B, D, and E (C has already been eliminated) and finally B, D, and B, so that D is the man who escapes.

Instead of giving the soldiers names you will assign them numbers serially starting from 1 (one). This way you can use the Link class that we discussed. In your program you will read the data from a file called josephus.txt. The first line gives the number of soldiers. The second line gives the soldier from where the counting starts. The third line gives the elimination number.

You will create a circular linked list having the number of soldier specified. Your program will print out the order in which the soldiers get eliminated. The template for your program will look like this:

```class Link(object):

class CircularList(object):
# Constructor
def __init__ ( self ):

# Insert an element in the list
def insert ( self, item ):

# Find the link with the given key
def find ( self, key ):

# Delete a link with a given key
def delete ( self, key ):

def deleteAfter ( self, start, n ):

# Return a string representation of a Circular List
def __str__ ( self ):

def main():

main()

```

You will modify the functions insert(), find(), and delete() from the LinkedList class. The main workhorse of the program will be the deleteAfter() method. This takes the starting Link and the elimination number n and deletes the nth Link from the starting Link. It returns the next Link after the Link that was deleted.

The file that you will be turning in will be called Josephus.py. The file will have a header of the following form:

```
#  File: Josephus.py

#  Description:

#  Student Name:

#  Student UT EID:

#  Course Name: CS 313E

#  Unique Number: 53260

#  Date Created: