C#,Linked List,最后两行有什么区别?

问题描述 投票:-6回答:1

需要知道最后两行之间的区别,我试图同时运行两个...第一个好的并显示全部,但第二个不请尽快回答我。

提前致谢

enter code here

 class node
 {
     public int data;
//next is a pointer
     public  node next;

     public node(int val)

     {
         data = val;   
     }

     public void print()
     {
         Console.WriteLine(data);   
     }
  }

  class list 
  {
     public node head;
     public string name;

     public list(string n)
     {
         name = n;
         head = new node(0);
     }

     public void addbegin(int newval)
     {
         node b = new node(newval);
         b.next = head.next;
  //  differnce between both
         head.next = b;
     }
c# object linked-list nodes
1个回答
0
投票

据我所知,您需要这两行代码才能正常工作。 b.next = head.next使b指向任何头指向(也就是列表中的第一个节点)。然后head.next = b在b点头。因此,这两行在链表的前面插入b。 Here is a link提供了有关链接列表的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.