私は理解するのに苦労しているコードを持っています。コードスニペット自体は、二重にリンクされたリストのコンストラクタです。しかし最後の行には次のように書かれています:(head = head.next).previous = null;これは、おそらく、配列aからノードを追加するために使用される一時的なノードを削除します。しかし、どのように機能するのですか?誰かがそれを明確かつ別々の行に分割することができれば、それは非常に役に立ちます。Javaで構文が混乱しています
// standard constructor
public DoublyLinkedList() {
head = tail = null;
numElements = 0;
changes = 0;
}
// constructor
public DoublyLinkedList(T[] a) {
this(); // call the standard constructor
Objects.requireNonNull(a, "a is null!");
head = tail = new Node<>(null); // a temporary node
for (T value : a) {
if (value != null) {
tail = tail.next = new Node<>(value, tail, null); // new node at the back
numElements++;
}
}
// remove the temporary node
if (numElements == 0) head = tail = null;
else (head = head.next).previous = null; // the problematic bit
}
これは論理質問か構文質問ですか?正確に何を理解していないのですか? – shmosel
@shmosel私はそれが文法の問題であると思う、コメントのおかげで。 –