本題要求實現乙個函式,將給定的單鏈表逆轉。
其中list結構定義如下:
l是給定單鏈表,函式reverse要返回被逆轉後的鍊錶。typedef
struct node *ptrtonode;
struct node
;typedef ptrtonode list;
/* 定義單鏈表型別 */
裁判測試程式樣例:
輸入樣例:#include
#include
typedef
int elementtype;
typedef
struct node *ptrtonode;
struct node
;typedef ptrtonode list;
list read()
;/* 細節在此不表 */
void
( list l )
;/* 細節在此不表 */
list reverse
( list l )
;int
main()
/* 你的**將被嵌在這裡 */
輸出樣例:513
452
首先是網上普遍的**,這個比較簡單,思路清晰。125
431
下面是我自己寫的**,比較麻煩,但其中一些問題需要記錄一下list reverse
( list l )
return p1;
}
總結起來,問題如下:list reverse
( list l )
q=p-
>next;
head=q;
while
(q!=l)
q->next=
null
;return head;
}
6 1 單鏈表逆轉 20分
本題要求實現乙個函式,將給定的單鏈表逆轉。函式介面定義 list reverse list l 其中list結構定義如下 typedef struct node ptrtonode struct node typedef ptrtonode list 定義單鏈表型別 l是給定單鏈表,函式revers...
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...