C language data structure list summary

Way linked list (headless cycle)
1. head plug

cur->next=head;
head=cur;

2. After the plug

cur->next=pos->next;
pos->next=cur;

3. Head deleted

tmp=head->next;
free(head);
head=tmp;

4. After puncturing

tmp=pos->next;
pos->next=tmp->next;
free(tmp);

5 traversing head

for(cur=head;cur;cur=cur->next)
{
    //通过cur遍历链表
}

6. Reverse single chain
<1>

oldhead->next=tmp->next;
tmp->next;=head;
head=tmp;
tmp=oldhead->next;

<2>

nt=nt->next;
cur->next==pre;
pre=cur;
cur=nt;

7. A circular linked list to find the link point
(1) to find the two pointers, a first step, a moving twice
(2) their encounter records node, then the node has been met and right-aligned start node
(3) Right after alignment, traversed together, to find the node first encounter, that is the ring node

Doubly linked list (loop lead)
1. Insert Operation

pos->next=cur;
cur->prev=pos;
tmp->prev=cur;
cur->next=tmp;

2. Delete operation

pos->prev->next=pos->next;
pos->next->prev=pos->prev;
free(pos);

3. traversal operation

for(cur->head->next;cur!=head;cur=cur->next)
{
     //cur进行遍历
}

4. merge operation
value 1. Comparative cur1 cur2 and, if a relatively small, then the backward jump directly cur1
2. If the value of 2 is relatively small, it will be inserted in front of the node before the node 1 is 2, then 2 Jump back
3. If the end of the cycle, out of 2, then the direct end
4. If the end of the cycle, one out, then all the remaining nodes 2 is inserted into the end of the 1

C language data structure list summary

Guess you like

Origin blog.51cto.com/14232799/2422502