- element.Value存储的是放在list的元素值
- 使用范例:
package main
import (
"container/list"
"fmt"
)
func printList(l *list.List){
for e := l.Front(); e!=nil;e = e.Next(){
fmt.Print(e.Value ," ")
}
fmt.Println("--------------------------")
}
func main() {
l := list.New()
for i := 0;i<=5;i++{
l.PushBack(i)
}
printList(l)
fmt.Println(l.Front().Value)
fmt.Println(l.Back().Value)
l.InsertAfter(6,l.Front())
printList(l)
l.MoveBefore(l.Front().Next(),l.Front())
printList(l)
l.MoveToFront(l.Back())
printList(l)
l2 := list.New()
l2.PushBackList(l)
printList(l2)
fmt.Println(l2.Len())
}
0 1 2 3 4 5 --------------------------
0
5
0 6 1 2 3 4 5 --------------------------
6 0 1 2 3 4 5 --------------------------
5 6 0 1 2 3 4 --------------------------
5 6 0 1 2 3 4 --------------------------
7