Detailed explanation of linked list ListNode

ListNode

When brushing LeetCode, I encountered a simple linked list question. The question already defined the linked list node ListNode. The author was very bad and forgot a lot, so I checked ListNode again.

struct ListNode {
    
    
       int val;    //定义val变量值,存储节点值
       struct ListNode *next;   //定义next指针,指向下一个节点,维持节点连接
  }

· In the node ListNodedefinition, define the node as a structure variable.
· The node stores two variables: valueand next. valueis the value of this node and nextis a pointer to the next node. When nextis a null pointer, this node is the last node of the linked list.
· Note that valit only represents the value of the current pointer, such as the value pointed by the pointer; and p->valrepresents the next node in the linked list, which is also a pointer. · The constructor contains two parameters , and , which are used to assign values ​​to nodes and specify the next node respectively.pp->next
_value_next

Guess you like

Origin blog.csdn.net/zhangqian_shai/article/details/106582662