Java singly linked list created / output --- basis:

Java code:

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);
    }
}

 

 operation result:

 

 

 

 

Published 84 original articles · won praise 0 · Views 706

Guess you like

Origin blog.csdn.net/qq_38405199/article/details/102982805