Java单向链表创建/输出---基础<Base>:
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); } }
运行结果: