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 ListNode
definition, define the node as a structure variable.
· The node stores two variables: value
and next
. value
is the value of this node and next
is a pointer to the next node. When next
is a null pointer, this node is the last node of the linked list.
· Note that val
it only represents the value of the current pointer, such as the value pointed by the pointer; and p->val
represents 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.p
p->next
_value
_next