作者joey11121 (Algorithmican)
看板C_and_CPP
標題[問題] Singly Linked List反轉
時間Wed Feb 19 23:28:34 2020
開發平台(Platform): (Ex: Win10, Linux, ...)
Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Dev-C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
最近在學習Linked List,想實作反轉Linked List,debug許久找不出為何無法印出反轉後的Linked List
餵入的資料(Input):
無
預期的正確結果(Expected Output):
21 -> 15 -> 7 -> 2 -> NULL
2 -> 7 -> 15 ->21-> NULL
錯誤結果(Wrong Output):
21 -> 15 -> 7 -> 2 -> NULL
2 -> NULL
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
https://ideone.com/eWq4t5
補充說明(Supplement):
-----
Sent from JPTT on my iPad
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 119.14.9.131 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1582126120.A.6A5.html
→ djshen: 不如說說你怎麼debug的 02/19 23:32
→ joey11121: 忘記考慮最後一個node不會進入while迴圈,已解決 02/19 23:51
→ joey11121: 所以迴圈結束後要再做一次curr -> next = prev 02/19 23:52