日期:2014-05-20 浏览次数:20868 次
public class Kie { int id; Kie left; Kie right; public Kie() { } public Kie(int id) { this.id=id; } public int getId() { return id; } public void setId(int id) { this.id = id; } public Kie getLeft() { return left; } public void setLeft(Kie left) { this.left = left; } public Kie getRight() { return right; } public void setRight(Kie right) { this.right = right; } public static void main(String []args) { Kie head=null; Kie last=null; Kie newF = null; for(int i=1;i<8;i++) { newF = new Kie(i); if(head==null) { head=newF; last = head; }else { last.right=newF; last = newF; } } head.left=last; last.right=head; // Kie k =head; // while(k.right!=head) // { // System.out.println(k.id); // k = k.right; // } // Kie node = head; while(node.left!=node.right||node.left==node.right&&node.left!=node) { node.right.right=node.right.right.right; node.right.right.left=node.right; node=node.right.right; //System.out.println(node.id); } System.out.println(node.id); } }
------解决方案--------------------
你还真拿对象造个环哦......
下面是我做的。
package KidsGame;
import java.util.ArrayList;
public class Kids {
int nowNumber=0;
public int GetNumber(){
return nowNumber++;
}
public void CallBack(){
nowNumber=1;
}
}
----------------------------------分割线---------------------------------
package KidsGame;
import java.util.ArrayList;