Question: Please help with this project! Node File: public class CDLL_Node { private T data; private CDLL_Node prev, next; // EACH CDLL_Node PTS TO ITS PREV
Please help with this project!


Node File:
public class CDLL_Node{ private T data; private CDLL_Node prev, next; // EACH CDLL_Node PTS TO ITS PREV & NEXT public CDLL_Node() { this( null, null, null ); // 3 FIELDS TO INIT } public CDLL_Node(T data) { this( data, null, null); } public CDLL_Node(T data, CDLL_Node prev, CDLL_Node next) { setData( data ); setPrev( prev ); setNext( next ); } public T getData() { return data; } public CDLL_Node getPrev() { return prev; } public CDLL_Node getNext() { return next; } public void setData(T data) { this.data = data; } public void setNext(CDLL_Node next) { this.next = next; } public void setPrev(CDLL_Node prev) { this.prev = prev; } public String toString() { return ""+getData(); } } //EOF
Starter File:
import java.io.*; import java.util.*; public class CDLL_JosephusList{ private CDLL_Node head; // pointer to the front (first) element of the list private int count=0; // private Scanner kbd = new Scanner(System.in); // FOR DEBUGGING. See executeRitual() method public CDLL_JosephusList() { head = null; // compiler does this anyway. just for emphasis } // LOAD LINKED LIST FORM INCOMING FILE public CDLL_JosephusList( String infileName ) throws Exception { BufferedReader infile = new BufferedReader( new FileReader( infileName ) ); while ( infile.ready() ) { @SuppressWarnings("unchecked") T data = (T) infile.readLine(); // CAST CUASES WARNING (WHICH WE CONVENIENTLY SUPPRESS) insertAtTail( data ); } infile.close(); } // ########################## Y O U W R I T E / F I L L I N T H E S E M E T H O D S ######################## // TACK ON NEW NODE AT END OF LIST @SuppressWarnings("unchecked") public void insertAtTail(T data) { } public int size() { return 0; } // RETURN REF TO THE FIRST NODE CONTAINING KEY. ELSE RETURN NULL public CDLL_Node search( T key ) { return null; } // RETURNS CONATENATION OF CLOCKWISE TRAVERSAL @SuppressWarnings("unchecked") public String toString() { return ""; } void removeNode( CDLL_Node deadNode ) { } public void executeRitual( T first2Bdeleted, int skipCount ) { if (size() curr = search( first2Bdeleted ); if ( curr==null ) return; // OK THERE ARE AT LEAST 2 NODES AND CURR IS SITING ON first2Bdeleted do { CDLL_Node deadNode = curr; T deadName = deadNode.getData(); // ** println( "stopping on curr.data to delete curr.data"); // BEFORE DOING ACTUAL DELETE DO THESE TWO THINGS // 1: you gotta move that curr off of the deadNode. // if skipCount poitive do curr=curr.next esle do curr=curr.prev // 2: check to see if HEAD is pointing to the deadnode. // If so make head=curr // NOW DELETE THE DEADNODE // println("deleted. list now: + toString() ); // toString prints the // if the list size has reached 1 return YOU ARE DONE. RETURN RIGHT HERE // ** println("resuming at curr.data, skipping curr.data + skipCount-1 nodes CLOCKWISE/COUNTERWISE after"); // write loop that advances curr pointer skipCount times (be sure of CLOCKWISE or COUNTER) // OPTIONAL HERE FOR DEBUGGING TO MAKE IT STOP AT BOTTOM OF LOOP // Scanner kbd = new Scanner( System.in ); String junk = kbd.nextLine(); } while (size() > 1 ); // ACTUALLY COULD BE WHILE (TRUE) SINCE WE RETURN AS SOON AS SIZE READES 1 } } // END CDLL_LIST CLASS
Tester File:
import java.io.*; import java.util.*; public class CDLL_JosephusTester { @SuppressWarnings("unchecked") public static void main( String args[] ) throws Exception { if ( args.length jCircle = new CDLL_JosephusList( infileName ); System.out.format( "jCircle pre ritual: %s ",jCircle ); jCircle.executeRitual( first2Bdeleted, skipCount ); System.out.format( "jCircle post ritual: %s Names.txt
Aronis HoffmanT Lange Lee Litman Marai Melhem Misurda Mosse Novacky Ramirez Znati
Background Project #5 will simulate the Josephus permutation, a mathematical problem modeled after the famous story about a small band of zealots in the first century that withstood the Roman army for a long period of time but eventually realized they were going to lose. They made a suicide pact to die rather than surrender. One of the zealots was Josephus Flavius. Josephus himself did not actually prefer death to surrender so one of the zealots devised a suicide ritual that gave himself and his best friend a way to survive. Josephus suggested they all stand in circle and go around the circle killing every third (or n'th) man until everyone was gone. According to legend Josephus was a mathematician and made sure that himself and his friend stood in the two spots that would be the last to kill themselves. Then after everyone else had died, he and his friend surrendered to the Romans. Josephus went on to become a famous historian of that century writing "the Antiquities" and other famous works that have endured till today. The Josephus problem is the prediction of who will be the last Node remainimg given a circle of N nodes, starting at a given node, and deleting every kith node in some direction CLOCKWISE or COUNTER_CLOCKWISE. Our program will not attempt an analytical solution. We will simulate the execution (no pun intended) of the algorithm until only one node remains. If you read about this problem on Wikipedia Josephus problem you will note they describe the algorithm as k meaning delete every k'th node such that k=2 two means delete every other node. Our assignment says k means skip k nodes in between deleting a node. This allows for our k value to be as small as 1 and still make sense. In our program k=1 means every other node in the list is deleted. Assignment Here is are the files you are given to work with: the CDLL Node.java class MERGE THIS INTO BOTTOM OF JOSEPHUS FILE. the CDLL_JosephusList.java class FILL IN THE METHODS AT BOTTOM the CDLL_Josephus Tester.java class DO NOT MODIFY Here is an input file of names to be loaded into the Nodes of the Joesphus list: names.txt Just as in the lab, our list is a CDLL. A CDLL can be traversed forward or backward, CLOCKWISE or COUNTER_CLOCKWISE. As we emulate the Josephus permutation deleting only every k'th node and skipping those in between, we also allow for this algorithm to be applied in a clock wise or counter clockwise manner on the list. AT NO TIME ARE ANY DUPES ALLOWED IN YOUR JOSEPHUS LIST BEFORE, DURING OR AFTER THE ALGORITHM COMPLETES. The method that gets called from out in the tester, that you must define in your JosephusList.java program, that traverses the list and calls remove on the Nodes will be named executRitual and will look like this: void executeRitural( String nameToStartWith, int direction, int skipCount ); If the skipCount is positive you are going CLOCKWISE (next). If negative you are going COUNTER CLOCKWISE (prev). 2 examples of execution from the command line Mac users will want to read this link in order to adapt these Windows/DOS batch files into unix scripts to run in the Terminal Window. $ java JosephusTester names.txt Hoffmant -3 $ java JosephusTester names.txt Znamti 5 0 $ Hoffman-3.bat now we execute this batch (bat) file. As it executes each line (command) it echoes it to the screen $ del *.class $ javac CDLL_Josephus Tester.java the last command is our execution of the CDLL_Josephus Tester feeding it the command line parameters we want $ java CDLL_Josephus Tester names.txt Hoffmant -3 jcircle pre ritual: AronisHoffmanTLangeLeeLitmanMaraiMelhemMisurdaMosseNovackyRamirezZnati stopping on Hoffmant to delete Hoffmant deleted. list now: AronisLangeLeeLitmanMaraiMelhemMisurdaMosseNovackyRamirezZnati resuming at Aronis, skipping Aronis + 2 nodes COUNTER_CLOCKWISE after stopping on Novacky to delete Novacky deleted. list now: AronisLangeLeeLitmanMaraiMelhemMisurdaMosseRamirezZnati resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on Marai to delete Marai deleted. list now: Aronis LangeLeeLitmanMelhemMisurda MosseRamirezZnati resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Aronis to delete Aronis deleted. list now: ZnatiLangeLeeLitmanMelhemMisurdaMosseRamirez resuming at Znati, skipping znati + 2 nodes COUNTER_CLOCKWISE after stopping on Misurda to delete Misurda deleted. list now: ZnatiLangeLeeLitmanMelhemMosseRamirez resuming at Melhem, skipping Melhem + 2 nodes COUNTER_CLOCKWISE after stopping on Lange to delete Lange deleted. list now: ZnatiLeeLitmanMelhemMosseRamirez resuming at znati, skipping znati + 2 nodes COUNTER_CLOCKWISE after stopping on Melhem to delete Melhem deleted. list now: znatiLeeLitmanMossec=>Ramirez resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Ramirez to delete Ramirez deleted. list now: ZnatiLeeLitmanMosse resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on znati to delete znati deleted. list now: MosseLeeLitman resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on Mosse to delete Mosse deleted. list now: Litman Lee resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Lee to delete Lee deleted. list now: Litman icinalonant itualitaan lobal atandinn Background Project #5 will simulate the Josephus permutation, a mathematical problem modeled after the famous story about a small band of zealots in the first century that withstood the Roman army for a long period of time but eventually realized they were going to lose. They made a suicide pact to die rather than surrender. One of the zealots was Josephus Flavius. Josephus himself did not actually prefer death to surrender so one of the zealots devised a suicide ritual that gave himself and his best friend a way to survive. Josephus suggested they all stand in circle and go around the circle killing every third (or n'th) man until everyone was gone. According to legend Josephus was a mathematician and made sure that himself and his friend stood in the two spots that would be the last to kill themselves. Then after everyone else had died, he and his friend surrendered to the Romans. Josephus went on to become a famous historian of that century writing "the Antiquities" and other famous works that have endured till today. The Josephus problem is the prediction of who will be the last Node remainimg given a circle of N nodes, starting at a given node, and deleting every kith node in some direction CLOCKWISE or COUNTER_CLOCKWISE. Our program will not attempt an analytical solution. We will simulate the execution (no pun intended) of the algorithm until only one node remains. If you read about this problem on Wikipedia Josephus problem you will note they describe the algorithm as k meaning delete every k'th node such that k=2 two means delete every other node. Our assignment says k means skip k nodes in between deleting a node. This allows for our k value to be as small as 1 and still make sense. In our program k=1 means every other node in the list is deleted. Assignment Here is are the files you are given to work with: the CDLL Node.java class MERGE THIS INTO BOTTOM OF JOSEPHUS FILE. the CDLL_JosephusList.java class FILL IN THE METHODS AT BOTTOM the CDLL_Josephus Tester.java class DO NOT MODIFY Here is an input file of names to be loaded into the Nodes of the Joesphus list: names.txt Just as in the lab, our list is a CDLL. A CDLL can be traversed forward or backward, CLOCKWISE or COUNTER_CLOCKWISE. As we emulate the Josephus permutation deleting only every k'th node and skipping those in between, we also allow for this algorithm to be applied in a clock wise or counter clockwise manner on the list. AT NO TIME ARE ANY DUPES ALLOWED IN YOUR JOSEPHUS LIST BEFORE, DURING OR AFTER THE ALGORITHM COMPLETES. The method that gets called from out in the tester, that you must define in your JosephusList.java program, that traverses the list and calls remove on the Nodes will be named executRitual and will look like this: void executeRitural( String nameToStartWith, int direction, int skipCount ); If the skipCount is positive you are going CLOCKWISE (next). If negative you are going COUNTER CLOCKWISE (prev). 2 examples of execution from the command line Mac users will want to read this link in order to adapt these Windows/DOS batch files into unix scripts to run in the Terminal Window. $ java JosephusTester names.txt Hoffmant -3 $ java JosephusTester names.txt Znamti 5 0 $ Hoffman-3.bat now we execute this batch (bat) file. As it executes each line (command) it echoes it to the screen $ del *.class $ javac CDLL_Josephus Tester.java the last command is our execution of the CDLL_Josephus Tester feeding it the command line parameters we want $ java CDLL_Josephus Tester names.txt Hoffmant -3 jcircle pre ritual: AronisHoffmanTLangeLeeLitmanMaraiMelhemMisurdaMosseNovackyRamirezZnati stopping on Hoffmant to delete Hoffmant deleted. list now: AronisLangeLeeLitmanMaraiMelhemMisurdaMosseNovackyRamirezZnati resuming at Aronis, skipping Aronis + 2 nodes COUNTER_CLOCKWISE after stopping on Novacky to delete Novacky deleted. list now: AronisLangeLeeLitmanMaraiMelhemMisurdaMosseRamirezZnati resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on Marai to delete Marai deleted. list now: Aronis LangeLeeLitmanMelhemMisurda MosseRamirezZnati resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Aronis to delete Aronis deleted. list now: ZnatiLangeLeeLitmanMelhemMisurdaMosseRamirez resuming at Znati, skipping znati + 2 nodes COUNTER_CLOCKWISE after stopping on Misurda to delete Misurda deleted. list now: ZnatiLangeLeeLitmanMelhemMosseRamirez resuming at Melhem, skipping Melhem + 2 nodes COUNTER_CLOCKWISE after stopping on Lange to delete Lange deleted. list now: ZnatiLeeLitmanMelhemMosseRamirez resuming at znati, skipping znati + 2 nodes COUNTER_CLOCKWISE after stopping on Melhem to delete Melhem deleted. list now: znatiLeeLitmanMossec=>Ramirez resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Ramirez to delete Ramirez deleted. list now: ZnatiLeeLitmanMosse resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on znati to delete znati deleted. list now: MosseLeeLitman resuming at Mosse, skipping Mosse + 2 nodes COUNTER_CLOCKWISE after stopping on Mosse to delete Mosse deleted. list now: Litman Lee resuming at Litman, skipping Litman + 2 nodes COUNTER_CLOCKWISE after stopping on Lee to delete Lee deleted. list now: Litman icinalonant itualitaan lobal atandinn Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
