// 链表定义
public class DueueTest
{
private int value;
public DueueTest next;
public DueueTest(int value)
{
this.value = value;
next = null;
}
public DueueTest()
{
this.value = 0;
next = null;
}
public int getValue()
{
return this.value;
}
}
// 为什么 head 没有被赋值成功
public class Main
{
public static void main(String[] args)
{
int n = 5;
DueueTest curr = new DueueTest();
DueueTest head = new DueueTest();
System.out.println("请输入5个数据: ");
Scanner scr = new Scanner(System.in);
for(int i = 0; i < n; i++)
{
DueueTest point = new DueueTest(scr.nextInt());
if (i == 0)
{
head = point; // 这里没有被赋值
curr = point; // 这里被赋值成功
}
else
{
curr.next = point;
curr = curr.next; // 这里被赋值成功
}
}
curr = head; // 同样这里 curr 没有被赋值成功
curr = curr.next // 这里同样没赋值成功
}
}