package main
import "fmt"
/*
双向链表
*/
type sxNode struct {
val int
next *sxNode
top *sxNode
}
func addNode(n *sxNode, i int) {
if n.next == nil {
newNode := &sxNode{val: i, top: n}
n.next = newNode
return
}
addNode(n.next, i)
}
func showNode(head *sxNode) {
for head != nil {
if head.top != nil {
fmt.Printf("top=%d ", head.top.val)
}
if head.next != nil {
fmt.Printf("next=%d ", head.next.val)
}
fmt.Println("val=", head.val)
head = head.next
}
}
func delNode(h *sxNode, i int) {
for h.next.val != i {
h = h.next
}
h.next.next.top = h.next.top
h.next = h.next.next
}
func main() {
head := &sxNode{val: 0, next: nil, top: nil}
addNode(head, 1)
addNode(head, 2)
addNode(head, 3)
addNode(head, 4)
addNode(head, 5)
delNode(head, 2)
showNode(head)
}