package main
import "fmt"
type node struct {
val int
next *node
}
func add(n *node, i int) {
if n.next == nil {
newNode := &node{val: i}
n.next = newNode
return
}
add(n.next, i)
}
func showLink(head *node) {
for head != nil {
fmt.Println(head.val)
head = head.next
}
}
func del(h *node, i int) {
for h.next.val != i {
h = h.next
}
h.next = h.next.next
}
func main() {
head := &node{val: 0, next: nil}
add(head, 1)
add(head, 2)
add(head, 3)
add(head, 4)
add(head, 5)
del(head, 2)
showLink(head)
}
go 链表
最新推荐文章于 2024-08-23 13:40:49 发布