SDUT 單鏈表逆置迴圈

2021-08-16 18:54:02 字數 775 閱讀 6395

time limit: 1000 ms

memory limit: 65536 kib

submit

statistic

problem description

輸入多個整數,以-1作為結束標誌,順序建立乙個帶頭結點的單鏈表,之後對該單鏈表的資料進行逆置,並輸出逆置後的單鏈表資料。

input

輸入多個整數,以-1作為結束標誌。

output

輸出逆置後的單鏈表資料。

sample input

12 56 4 6 55 15 33 62 -1

sample output

62 33 15 55 6 4 56 12

hint

不得使用陣列。

source

#include#includetypedef struct nodenode;

void createlist(node *&h)while(a!=-1);

r->next=null;

}void printlist(node *h)

}node* reverselist(node *h)

node *p,*k;//p為最終指向有效資料鏈,k一直往前 ,最終返回h

p=null;

k=h->next;

while(k)

h->next=p;

return h;

}int main()

單鏈表逆置

單鏈表逆置 include include define item num 10 typedef struct tagnode node node linklist create void linklist destroy node head void linklist print node hea...

單鏈表逆置

name 單鏈表逆置 author 巧若拙 date 22 11 14 16 13 description 分別用遞迴和非遞迴兩種方式實現單鏈表 不含頭結點 的逆置 include include include typedef char elemtype typedef int status 函式...

單鏈表逆置

最近在leetcode oj上刷題,將一些演算法題的解法記錄下來,也期待一些新的更好的方法。題目是這樣滴 206.reverse linked list reverse a singly linked list.hint a linked list can be reversed either it...