import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;
public class DequeueNumThree {
//数组
public static void MethodArr(){
System.out.println("Please input total people : ");
Scanner scanner = new Scanner(System.in);
int totalPeople = scanner.nextInt();
boolean[] arr = new boolean[totalPeople];
for(int i = 0; i < arr.length; i++){
arr[i] = true;
}
int count = 0;//报数 1 2 3
int leftPeople = totalPeople;//去掉报道3之后剩余的人数
int index = 0;//数组下标
while(leftPeople > 1){//最后只能剩余一个人
if(arr[index] == true){//如果当前状态为true
count++;//报数
if(count == 3){//如果报数为3
arr[index] = false;//状态设置成false
count = 0;//为下次重新报数做准备
leftPeople--;//剩余人数减一
}
}
index++;//到下一个人了
if(index == totalPeople){//如果到最后一个人了,那么,从头重新开始报数
index = 0;
}
}
for(int i = 0; i < totalPeople; i++){
if(arr[i] == true){
System.out.println("last number is " + (i+1));
}
}
}
}
//链表
package test01;
import java.util.LinkedList;
import java.util.List;
public class forxx {
/**
* @param args
*/
public static int cycle(int total,int k){
List dataList = new LinkedList();//创建一个链表
for(int i=0;i
dataList.add(new Integer(i+1));
int index=-1;
//循环
while(dataList.size()>1){
index = (index+k)%dataList.size();//以(index+k)对size()取余
dataList.remove(index--);
}
return ((Integer)dataList.get(0).intValue());//返回它的值
}
public static void main(String[] args) {
System.out.println("该人原来的位置是: "+cycle(10000,3));
}
}