Import Java.util.arraylist;import java.util.list;/** * Circled, queued for the last person * @author fjza1168 * */public class Qlastpeople {/** * * @param list of people * @param num per num person, dequeue one person * @return */public static int getlast (list<integer> list, int num) {int total = List.size (), int count =0;while (total>1) {list<integer> temp = new arraylist<integer> (); for ( int i=0;i<total;i++) {count++;if (count%num!=0) {Temp.add (List.get (i)); System.out.println (count+ "::" +list.get (i));}} List = Temp;total = List.size ();} Return List.get (0);} public static void Main (String [] args) {list<integer> List = new arraylist<integer> (); for (int i=1;i<=10;i + +) {list.add (i);} System.out.println (GetLast (list, 4));}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The problem of queue count in the Java Circle, method