Question: Help In JAVA: The Josephus problem. It will be peer reviewed, so make SURE you eliminate all references to you. This means take out your

Help In JAVA: The Josephus problem. It will be peer reviewed, so make SURE you eliminate all references to you. This means take out your name and all comments inserted by NetBeans where it says "author", otherwise the peer reviewers will know who they are reviewing. Use words.txt as input. Use the Node class and the Circular Queue class you created. In your main program input the words from words.txt into a Queue (a circular queue) - do this by using enqueue .Then input an integer (n). Then starting at the head of the queue delete every nth node until only one node remains. Output the String in that last node. Make NO changes to the Node class. In the Queue class you will need a method to delete every nth node.You will need to print your queue, so make a print method in your Queue class. This should print the ENTIRE queue, not just the head. It is true that at the end only the head should remain, but by printing the entire queue and finding there is only one node printed you are verifying to me (and to yourself) that only the head remains.

words.txt:

noncollectable

reallocation

drenching

obnoxious

venality

dybbuk

shotgun

changelessly

handiwork

unheralded

dovecote

anode

spellbind

psychologist

improvisational

prejudiced

apply

pokey

secular

masterfully

at

node class:

public class Node { //node class Object item; Node next;

Node(Object newItem) { item = newItem; next = null; }

Node(Object newItem, Node nextNode) { item = newItem; next = nextNode; } }

queue class:

public class Queue {

private Node head; private Node tail; private int size;

public Queue() { head = null; tail = null; size = 0; }

//enqueue public void enqueue(T item) { Node temp = new Node(item); if (head == null) { head = temp; tail = temp; } else { tail.next = temp; tail = temp; }

size++; }

//dequeue public T dequeue() { Node temp = head; head = head.next; temp.next = null; size--; return (T) temp.item; }

//isEmpty public boolean isEmpty() { return (size == 0); } public int size(){ if (size==0){ } return size; } //print public void print() { Node curr = head; while (curr != null) { System.out.println(curr.item); curr = curr.next; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!