static class Node {
int data;
Node next;
Node(int v) {
data = v;
}
}//成员类,代表节点,类似于C++语言中的结构体
static Node head = new Node(1);//头节点单列出来
static void init() {
Node x = head;
for (int i = 1; i <= 10; i++) x = (x.next = new Node(i));//建立单向链表
x.next = null;
}
这是一个链表的部分的代码
请问其中的 x = (x.next = new Node(i));这一句是什么意思;
还可以怎么表示?(还可以写成哪几句?)
x = (x.next = new Node(i));
// 这一条语句其实是将两条合并在一起了,没合在一起应该是下面这样的
// 主要的作用就是,给当前x节点赋值,然后在到下一个节点对下下个节点赋值
x.next = new Node(i);
x = x.next;