鍊錶的插入 刪除

2021-10-05 16:48:42 字數 572 閱讀 9222

雙向鍊錶的插入

第一步:首先找到插入位置,節點 s 將插入到節點 p 之前

第二步:將節點 s 的前驅指向節點 p 的前驅,即 s->prior = p->prior;

第三步:將節點 p 的前驅的後繼指向節點 s 即 p->prior->next = s;

第四步:將節點 s 的後繼指向節點 p 即 s->next = p;

第五步:將節點 p 的前驅指向節點 s 即 p->prior = s;

雙向鍊錶的刪除

第一步:找到即將被刪除的節點 p

第二步:將 p 的前驅的後繼指向 p 的後繼,即 p->prior->next = p->next;

第三步:將 p 的後繼的前驅指向 p 的前驅,即 p->next->prior = p->prior;

第四步:刪除節點 p 即 delete p;

鍊錶插入刪除

include include typedef struct node node,linklist void createlist linklist head 建立鍊錶 s node malloc sizeof node s next null s data data p next s p s in...

鍊錶的插入 刪除

include include include define true 1 define false 0 define ok 1 typedef struct l list list,plist plist create list int len 建立乙個單鏈表 bool show list pli...

鍊錶插入刪除操作

include using namespace std 定義單向鍊錶節點 struct listnode end of listnode 將新節點插入煉表頭 void insertlist listnode head,int insertdata listnode pnode new listnod...