顺序打印链表
package main
import (
"fmt"
)
// 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
func main() {
head := &Node{1, &Node{2, &Node{3, &Node{4, &Node{5, nil}}}}}
PrintListFromTailToHead(head)
}
type Node struct {
Data interface{}
Next *Node
}
func PrintListFromTailToHead(listNode *Node) {
for current := listNode; current != nil; current = current.Next {
fmt.Print(current.Data, ", ")
}
fmt.Println("")
}