1 Public classJosephus {2 Static classnode{3 intVal;4 Node Next;5Node (intv) {6Val=v;7 } 8}//member class, representing a node, similar to a struct in a data structure9 Public Static voidMain (string[] args) {Ten intn=9;//This represents the total number of people One intm=5;//count to a few people out of the ANode t=NewNode (1);//the head node is listed separately to facilitate the formation of a circular chain list -Node x=T; - the for(inti=2;i<=n;i++) x= (x.next=NewNode (i));//set up one-way linked list -x.next=t;//the next point of the last node points to the first node, forming a circular list -SYSTEM.OUT.PRINTLN ("The Order of the Rings is:"); - while(x!=X.next) { + for(inti=1;i<m;i++) -x=X.next; + //at this point, X is the previous node of the node that will be dequeue ASystem.out.print (x.next.val+ ""); atx.next=X.next.next; - } - System.out.println (); -System.out.println ("Survivors is" +x.val); -} -}
Java Loop link List implementation Joseph Ring (handling)