單向鏈表(無頭無循環)
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的末尾