作者Neisseria (Neisseria)
看板C_and_CPP
標題[討論] list traversal
時間Wed Apr 18 15:01:00 2018
一般來說,內部大概就是用 while 搭配 pointer 走訪
但是不是要弄個外部介面會比較好?整個 Node 暴露在外總是怪怪的
目前想到有兩種:
- 迭代器,可參考:
https://pastebin.com/44qP3nKx
- 高階函式的 map,可參考:
https://pastebin.com/K4ewLWt2
貼起來有點長,請大家自點連結
我直覺上覺得是用迭代器,但某本計概課本這樣描述 list traversal:
traverse(listName, action)
感覺起來就是用高階函式
最後補上小弟的實作,大家參考參考:
https://github.com/cwchentw/CLangDoublyLinkedList
這只是防止被板主劣退的自保手段 XD
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.105.249.161
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1524034866.A.191.html
→ wtchen: 板工又不是自己喜歡退文(蹲角落畫圈圈) 04/18 15:22
推 chuegou: 寫code要防呆 寫文要防退 04/18 18:59
推 Qbsuran: 可以考慮用看看callback 04/18 19:29
※ 編輯: Neisseria (60.251.46.166), 12/24/2018 16:58:10