package com.link.night;
class Child12{
int no;
Child12 nextChild=null;
public Child12(int no){
this.no=no;
}
}
class FindChild{
int first,num;
Child12 temp=null;
Child12 firstChild=null;
int len;
public void CycChild(){
for (int i = 1; i <= len; i++) {
Child12 ch=new Child12(i);
if(i==1){
temp=ch;
firstChild =ch;
}else if(i==len){
temp.nextChild=ch;
temp=ch;
temp.nextChild=firstChild;
}else{
temp.nextChild=ch;
temp=ch;
}
}
}
public void Setlen(int len){
this.len=len;
}
public void Show(){
Child12 temp=firstChild;
do{
System.out.println(temp.no);
temp=temp.nextChild;
}while(temp!=firstChild);
}
public void First(int first){
this.first=first;
}
public void Num(int num){
this.num=num;
}
public void How(){
Child12 temp=firstChild;
for (int i = 1; i <= first; i++) {
temp=temp.nextChild;
}
while(temp.nextChild!=null){
for (int j = 1; j <=num; j++) {
temp=temp.nextChild;
if(j==num-1){
temp.nextChild=temp.nextChild.nextChild;
}
}
} System.out.println(temp.no);
}
}
public class TestLink{
public static void main(String[] args) {
FindChild sir =new FindChild();
sir.Setlen(4);
sir.CycChild();
sir.Num(2);
sir.First(2);
sir.Show();
//sir.How();最终要完成这个方法,但目前不成功,死循环,
}
} |
|