package com.zb.swdata.core;标签:Node,nodelist,cur,nextnode,算法,num,量化,public From: https://www.cnblogs.com/chengxin1982/p/16836750.html
public class Test {
public static class Node{
public Node nextnode;
private Integer num;
public Node get(){
return nextnode;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public void run(){
Node[] nodelist = new Node[100];
Node nodetmp = null;
for(int i= 0; i < nodelist.length; i++ ){
nodelist[i] = new Node();
nodelist[i].num = i + 1;
if (i == 0) {
nodetmp = nodelist[i];
continue;
}
else {
nodetmp.nextnode = nodelist[i];
nodetmp = nodelist[i];
}
}
nodelist[99].nextnode = nodelist[0];
Node cur = nodelist[0];
while (cur != cur.nextnode){
Node tmp1 = cur.nextnode.nextnode;
cur.nextnode = cur.nextnode.nextnode;
cur = tmp1;
System.out.println(cur.num);
}
System.out.println(cur.num);
}
}
public static void main(String[] args){
Node node = new Node();
node.run();
}
}