java自建链表
class struct{
public int value;
public struct next;
struct(int value,struct next){
this.value=value;
this.next=next;
}
struct(){
next=null;
}
}
public class MyLinkedList {//1 1 1 2
public static void main(String[] args) {
int a[]={1,2,5,8,9};
struct end=new struct(a[a.length-1],new struct());
struct temp=end;
for(int i=a.length-2;i>=0;i--){
temp=new struct(a[i],temp);
}
int i=1;
while(temp.next!=null){
System.out.println("第"+i+"个数为:"+temp.value);
i++;
temp=temp.next;
}
}
}