鍊錶 1 鍊錶中資料的刪除

2022-04-01 02:38:28 字數 552 閱讀 8176

這是乙個在鍊錶中刪除特定字元的**,學習鍊錶後第一次編寫的乙個**。

1 #include 2 #include 3 #include 4 #include 5 #include 6

using

namespace

std;

7structsa8

;12int show(sa *t)//

列印鍊錶

1319

return0;

20}21int del(sa *t,char data)//

清除指定的單字元

2230 t=t->next;31}

32return0;

33}34int

main()

3548 p->next=null;//

空間鏈結束的標誌

49 cin>>data;

50del(q,data);

51show(q);52}

53return0;

54 }

view code

lintcode 鍊錶 刪除鍊錶中的元素

刪除鍊錶中等於給定值val的所有節點。給出鍊錶 1 2 3 3 4 5 3,和 val 3,你需要返回刪除3之後的鍊錶 1 2 4 5 判斷鍊錶是否為空,若是,返回null,若不是,進行下一步 判斷鍊錶第乙個結點是否為要刪除的結點,若是,將head指標向後移,若不是,無需操作 定義指標pre,判斷當...

鍊錶 刪除鍊錶中重複的節點

刪除鍊錶中重複的節點 方法一 採用遞迴的方法,但這種方法在鍊錶無重複節點時效率不高 function deleteduplication phead if phead.val phead.next.val return deleteduplication node 採用遞迴的方法從下乙個不重複的點開...

鍊錶 刪除鍊錶中重複的節點

刪除鍊錶中重複的節點 方法一 採用遞迴的方法,但這種方法在鍊錶無重複節點時效率不高 function deleteduplication phead if phead.val phead.next.val return deleteduplication node 採用遞迴的方法從下乙個不重複的點開...