type LinkNode struct {
data int
next *LinkNode
}
func reverseNode(node *LinkNode) {
if node == nil {
return
}
result := list.New()
for i := node; i != nil; i = node.next {
fmt.Println(i.data)
result.PushFront(i.data)
}
//反向遍历
for v := result.Back(); v != nil; v = v.Prev() {
fmt.Println(v.Value)
}
}
func main() {
node := LinkNode{data: 1}
next := LinkNode{data: 2}
node.next = &next
reverseNode(&node)
}
有疑问加站长微信联系(非本文作者)