習題11 7 奇數值結點鍊錶

2021-10-07 16:38:31 字數 1355 閱讀 5322

習題11-7 奇數值結點鍊錶 (20分)

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表、將鍊錶中奇數值的結點重新組成乙個新的鍊錶。鍊錶結點定義如下:

struct listnode ;
struct listnode *readlist();

struct listnode *getodd( struct listnode **l );

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

函式getodd將單鏈表l中奇數值的結點分離出來,重新組成乙個新的鍊錶。返回指向新煉表頭結點的指標,同時將l中儲存的位址改為刪除了奇數值結點後的鍊錶的頭結點位址(所以要傳入l的指標)。

#include #include struct listnode ;

struct listnode *readlist();

struct listnode *getodd( struct listnode **l );

void printlist( struct listnode *l )

printf("\n");

}int main()

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

1 2 2 3 4 5 6 7 -1
1 3 5 7 

2 2 4 6

struct listnode *readlist(  )

else exit( 1 );

if( head != null )

else head = q;

p = q;

}return head; }

struct listnode *getodd( struct listnode **l )

else exit( 1 );

if( head1 != null )

else head1 = q;

p1 = q;

}

else

else exit( 1 );

if( head0 != null )

else head0 = q;

p0 = q;

}*l = ( *l ) -> next;

}*l = head0;

return head1;

}

11 7 奇數值結點鍊錶

奇數值結點鍊錶 輸入若干個正整數 輸入 1為結束標誌 建立乙個單向鍊錶,頭指標為l,將鍊錶l中奇數值的結點重新組成乙個新的鍊錶new,並輸出新建鍊錶的資訊。鍊錶結點定義 struct listnode 函式介面定義 struct listnode readlist struct listnode g...

習題11 7 奇數值結點鍊錶 20 分

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中奇數值的結點重新組成乙個新的鍊錶。鍊錶結點定義如下 struct listnode 函式介面定義 struct listnode readlist struct listnode getodd struct listnode l 函式rea...

習題11 7 奇數值結點鍊錶 20分

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表 將鍊錶中奇數值的結點重新組成乙個新的鍊錶。鍊錶結點定義如下 這題最後題目要返回新的鍊錶的頭結點,但是編譯錯誤,返回首元節點則對,不知道為什麼。struct listnode struct listnode readlist return head ...