ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 遍历 前序和后续遍历在对链表做操作时,可以有助于理解 ### 前序 ``` func iter(head *Node) { if head == nil || head.next == nil { return } fmt.Printf("%+v\n", head.val) iter(head.next) } //output //1 //2 //3 //4 //5 ``` ### 后续 ``` func iter(head *Node) { if head == nil || head.next == nil { return } iter(head.next) fmt.Printf("%+v\n", head.val) } //output //5 //4 //3 //2 //1 ```