java吧 关注:1,223,482贴子:12,677,715
  • 2回复贴,共1

环链列表,不知错那里,有空的帮忙看看

只看楼主收藏回复

跟住打,可能近视加深了,看不到那错了
韩顺平.循序渐进学.java.从入门到精通.第11讲-约瑟夫问题.avi
那个
public class a{
public static void main(String[] args) {
CycLink cyclink = new CycLink();
cyclink.setLen(5);
cyclink.createLink();
cyclink.show();
}
}
class Child{
int no;
Child nextChild = null;
public Child(int no){
this.no =no;
}
}
class CycLink{
//先定义一个指向链表第一个小孩的
Child firstChild =null;
Child temp=null;
int len =0; //共有多少个小孩
//设置链大小
public void setLen(int len){
this.len=len;
}
//初始化环形链表
public void createLink(){
for(int i=1;1<=len;i++){
if(i==1){
Child ch = new Child(i);
this.firstChild=ch;
this.temp=ch;
}
else{
if (i==len){
Child ch =new Child(i);
temp.nextChild=ch;
temp=ch;
temp.nextChild=this.firstChild;
}
else{
Child ch =new Child(i);
temp.nextChild=ch;
temp=ch;
}
}
}
}
public void show(){
Child temp=this.firstChild;
do{
System.out.println(temp.no);
temp=temp.nextChild;
}
while(temp!=this.firstChild);
}
}


1楼2014-12-26 01:02回复
    我不喜欢韩顺平,逻辑啰嗦的没条理。他的视频适合1.5倍速观看。


    来自Android客户端2楼2014-12-26 08:07
    收起回复