Singly linked list comprehension

1. The node type defines: a custom type structure, comprising two members ① ② pointer field and a data field

Wherein the node pointer field is a pointer type

如typedef struct LNode

{

ElemType data; // domain data fields, the data stored in the node (type base type)

struct LNode * next; // LNode type (i.e., variable type pointing LNode) pointer next;

}LNode;*LinkList;

Understand code: ① define a specific data type struct LNode, comprising two members, named pointer field and data field.

Wherein LNode pointer field is a pointer type.

② use the data type typedef name change 

Equivalent typedef struct LNode LNode; struct // If the name change LNode LNode, subsequent use of this type can be omitted define the variable struct

And typedef struct LNode * LinkList; // pointer to the struct Lnode type (referred to as int * int type pointer type) transducer called LinkList

⇒LinkList type is a pointer type of pointer LNode

2. Access Node (structural body) member (a pointer data field and the next field data)

① normal access: LNode ln1; ln1.data;

② pointer visit: LinkList p; (* p) .data;

③ → Access: LinkList p; p → data; equivalent (* p.data)

Note: p → next (* p.next); has two meanings

①P node pointer to the domain (where p → next address variable)

The successor node pointers ②P junction point (where p → next pointer variable)

Method respectively - was observed before and after the variable.

The LinkList L; // define a head pointer

LinkList P; // Define a position pointer (marked node currently pointed to)

p = L → next; // initialize the p-point to the first node (the first node element), because the equivalent to the (* p) .next,

And p is a pointer variable, so that only L → next pointer variables (head node * successor node pointer p)

 

Guess you like

Origin blog.csdn.net/qq_41850194/article/details/91492623