Intro DS: Queues
The following explanation of Queues is taken from Wikipedia:
In computer science, a queue (/ˈkjuː/ kew) is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the queue a First-In-First-Out (FIFO) data structure.
In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed. Often a peek or front operation is also entered, returning the value of the front element without dequeuing it. A queue is an example of a linear data structure, or more abstractly a sequential collection.
Queues provide services in computer science, transport, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.
Queues are common in computer programs, where they are implemented as data structures coupled with access methods, as an abstract data structure or in object-oriented languages as classes. Common implementations use arrays or linked lists.
Queues are often created as a circular data structure - called a Circular Queue.
Circular Queue Project: The Josephus ProblemThe following video will help you understand the basics of the Josephus problem in mathematics.
Project DescriptionImplement the Josephus scenario as a circular queue using a linked list of ListNodes. Modify the LinkedList class you made previously to turn it into a CircularQueue class. Give each ListNode on the Queue an ID number. Add the boolean property hasSword to the ListNode class. At any given time, only one ListNode in the CircularQueue should have a true value for its hasSword property. When the queue is first created, the first node (node #1) should have the sword.
Terminate each simulation when there is only one node remaining. Run the simulation for n values from 1 to 100. Print the "winning" seat number for each case. Use the data you have collected to come up with a formula for the winning seat number.