C语言数据结构 链表总结

单向链表(无头无循环)
1.头插数据结构

cur->next=head;
head=cur;

2.后插ide

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

3.头删指针

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

4.后删code

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

5遍历头blog

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

6.反转单链表
<1>it

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

<2>class

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

7.循环链表找入环节点
(1)找两个指针,一个一次走一步,一个一次走两步
(2)记录他们的相遇节点,此时相遇节点和起始节点已经右对齐
(3)右对齐后,一块儿遍历,找第一次相遇的节点,就是入环节点循环

双链表(带头循环)
1.插入操做遍历

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

2.删除操做im

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

3.遍历操做

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

4.合并操做
1.比较cur1和cur2的值,若是1比较小,那么cur1直接向后跳转
2.若是2的值比较小,那么将2的这个节点前插到1的节点前面,而后2向后跳转
3.若是循环结束后,2跳出,那么直接结束
4.若是循环结束后,1跳出,那么将2的剩余全部节点插入到1的末尾

C语言数据结构  链表总结

相关文章
相关标签/搜索