實驗11 2 8 單鏈表結點刪除 20分

2021-10-04 06:17:03 字數 1405 閱讀 4245

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表、將鍊錶中所有儲存了某給定值的結點刪除。

函式介面定義:

struct listnode *

readlist()

;struct listnode *

deletem

(struct listnode *l,

int m )

;

函式readlist從標準輸入讀入一系列正整數,按照讀入順序建立單鏈表。當讀到−1時表示輸入結束,函式應返回指向單鏈表頭結點的指標。

函式deletem將單鏈表l中所有儲存了m的結點刪除。返回指向結果煉表頭結點的指標。

裁判測試程式樣例:

#include

#include

struct listnode

;struct listnode *

readlist()

;struct listnode *

deletem

(struct listnode *l,

int m )

;void

printlist

(struct listnode *l )

printf

("\n");

}int

main()

/* 你的**將被嵌在這裡 */

輸入樣例:

10

1110

1210-1

10

輸出樣例:

11

12

通過**:

//建立鍊錶

struct listnode *

readlist()

return head;

}//刪除鍊錶中的節點

struct listnode *

deletem

(struct listnode *l,

int m )

if(l ==

null

)return

null

;//如果刪空了則直接返回null

//處理正常情況

p = l;

tail = p -> next;

while

(tail !=

null

)else p = tail;

tail = p -> next;

}return l;

}

實驗11 2 8 單鏈表結點刪除 (20 分)

實驗11 2 8 單鏈表結點刪除 20 分 本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中所有儲存了某給定值的結點刪除。鍊錶結點定義如下 struct listnode 函式介面定義 struct listnode readlist struct listnode deletem st...

實驗11 2 8 單鏈表結點刪除 20分

題目 本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中所有儲存了某給定值的結點刪除。鍊錶結點定義如下 struct listnode 函式介面定義 struct listnode readlist struct listnode deletem struct listnode l,int...

實驗11 2 8 單鏈表結點刪除 20分

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中所有儲存了某給定值的結點刪除。鍊錶結點定義如下 struct listnode 函式介面定義 struct listnode readlist struct listnode deletem struct listnode l,int m ...