鱼C论坛

 找回密码
 立即注册
查看: 2643|回复: 2

丢手绢问题(部分)

[复制链接]
发表于 2018-6-11 09:23:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
exclipse总说我的那一行有 java.lang.NullPointerException,但是我是跟着一个视频上面打的啊,不应该有错啊!!!
class midnight {

        public static void main(String[] args) {
                // TODO Auto-generated method stub
      cyclink cyclink1=new cyclink();
      cyclink1.setlength(5);
      cyclink1.createlink();
      cyclink1.show();
        }

}

class child{
        int node;
        child nextchild;
        public child(int node) {
                this.node=node;
        }
}
//构成环形链表
class cyclink{
        //先定义一个指向链表头的
        //指向第一个小孩的不能动
        child temp;
    child firstchild;
        int len=0;//表示共有几个小孩
        public void setlength(int len) {
                this.len=len;
        }
        //初始化环形链表
        public void createlink() {
                for(int i=0;i<=len;i++) {
                        //创建第一个小孩
                        if(i==1) {
                        child ch=new child(i);
                        this.firstchild=ch;
                        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.node);
                temp=temp.nextchild;
        }while(temp!=this.firstchild);
}
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-7-17 11:05:59 | 显示全部楼层
写了半天,瞅一眼吧。
鱼c1.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 23:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表