我在一本书中看到了这个单链表实现。但是,我不明白一些陈述。我针对每个陈述的问题都列在每个陈述中。
1 class Node {
2 Node next = null; //Is this a constructor?
3 int data;
4 public Node(int d) { data = d; }
5 void appendToTail(int d) {
6 Node end = new Node(d);
7 Node n = this;//Why is "this" keyword used here? What does this do?
8 while (n.next != null) { n = n.next; }//Where does "next" member come from?
9 n.next = end;
10 }
11 }
答案 0 :(得分:1)
2 Node next = null; //Is this a constructor? NO it is not.
4 public Node(int d) { data = d; } //This is constructor
7 Node n = this; //The this keyword refers to the current instance of the class
8 while (n.next != null) { n = n.next; } //Learn Linked list