Java单向链表创建/输出---基础:

Java代码:

package com.linked;

class A{
    public  int data;
    public  A next=null;
    public A(){
    }
    public A(int data,A next){
        this.data=data;
        this.next=next;
    }
}
public class Test {
    public static void main(String[] args) {
        A p=new A(0,null);
        A head=p;
        for (int i=1;i<10;i++){
            A e=new A(i,null);
            p.next=e;
            p=e;
        }
       while(head.next!=null){
           System.out.print(head.data);
           head=head.next;
       }
        System.out.print(head.data);
    }
}

 运行结果:

发布了84 篇原创文章 · 获赞 0 · 访问量 706

猜你喜欢

转载自blog.csdn.net/qq_38405199/article/details/102982805
今日推荐