6 1 單鏈表逆轉 20分

2021-10-07 06:59:43 字數 1157 閱讀 6432

本題要求實現乙個函式,將給定的單鏈表逆轉。

函式介面定義:

list reverse

( list l )

;

其中list結構定義如下:

typedef

struct node *ptrtonode;

struct node

;typedef ptrtonode list;

/* 定義單鏈表型別 */

l是給定單鏈表,函式reverse要返回被逆轉後的鍊錶。

裁判測試程式樣例:

#include

#include

typedef

int elementtype;

typedef

struct node *ptrtonode;

struct node

;typedef ptrtonode list;

list read()

;/* 細節在此不表 */

void

print

( list l )

;/* 細節在此不表 */

list reverse

( list l )

;int

main()

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

輸入樣例:

513

452

輸出樣例:

125

431

list reverse

(list l)

l = l1;

/*退出迴圈時,l2為空,即指向了最後乙個非空結點的下乙個結點,則用於儲存l2左結點資料的

l1指向了原鍊錶的最後乙個非空結點,其實剛開始讓l1->next = null;已經說明了最終的頭結點

跟l1有關,很容易想到,將原鍊錶的頭結點改為尾結點,即l1的位置,返回頭結點

*/return l;

}

6 1 單鏈表逆轉 20分

本題要求實現乙個函式,將給定的單鏈表逆轉。其中list結構定義如下 typedef struct node ptrtonode struct node typedef ptrtonode list 定義單鏈表型別 l是給定單鏈表,函式reverse要返回被逆轉後的鍊錶。裁判測試程式樣例 includ...

6 1 單鏈表逆轉 20 分

本題要求實現乙個函式,將給定的單鏈表逆轉。list reverse list l 其中list結構定義如下 typedef struct node ptrtonode struct node typedef ptrtonode list 定義單鏈表型別 l是給定單鏈表,函式reverse要返回被逆轉...

6 1 單鏈表逆轉 20分

list reverse list l typedef struct node ptrtonode struct node typedef ptrtonode list 定義單鏈表型別 include include typedef int elementtype typedef struct no...