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 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 public String toString() { return ""; } void removeNode( CDLL_Node deadNode ) { } public void executeRitual( T first2Bdeleted, int skipCount ) { if (size() <= 1 ) return; CDLL_Node 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 // COPY THE NODE CLASS INTO HERE THEN DELETE YOUR NODE.JAVA file // REMOVE ALL PUBLIC AND REMOVE SETTERS GETTERS // LEAVE PUBLIC ONLY ON TOSTRING