遍历

最后更新于:2022-04-02 04:22:15

[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 ```
';