头结点
Node.java
package fvti;
public class Node{
int data;
Node next;
public Node()
{
next=null;
}
public Node(Node d){
data=d.data;
next=d.next;
}
public Node(int v){
data=v;
next=null;
}
}
运行结点
T.java
package fvti;
import java.util.Scanner;
public class T {
public static void main(String[] args){
Node head = new Node();
Node t,p;
int n,i,v;
Scanner sc=new Scanner(System.in);
System.out.println("请问有多少个数据n=");
n=sc.nextInt();
System.out.println("请输入他们的值");
p=head;
for(i=1;i<=n;i++){
v=sc.nextInt();
t=new Node(v);
p.next=t;
p=t;
}
t= head.next;
while(t!=null){
System.out.print(t.data+" ");
t=t.next;
}
System.out.println();
}
}