【问题标题】:Singly linked code explanation单链接代码说明
【发布时间】:2013-11-20 05:42:08
【问题描述】:

我在一本书中遇到了这个单链表实现。但是,我不明白一些说法。我对每个陈述的问题都针对每个陈述列出。

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 }

【问题讨论】:

    标签: c# singly-linked-list


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-04
      • 2012-06-25
      • 1970-01-01
      • 2013-09-12
      • 2017-01-23
      • 2014-09-21
      • 2016-06-01
      • 2015-01-13
      相关资源
      最近更新 更多