|
@@ -0,0 +1,52 @@
|
|
|
+//https://books.studygolang.com/The-Golang-Standard-Library-by-Example/chapter03/03.3.html
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "container/list"
|
|
|
+ "fmt"
|
|
|
+ "reflect"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ fmt.Println("hello")
|
|
|
+ // insertPushList()
|
|
|
+ listAddrness()
|
|
|
+}
|
|
|
+
|
|
|
+func insertPushList() {
|
|
|
+ // 创建一个新的链表,并向链表里面添加几个数字
|
|
|
+ l := list.New()
|
|
|
+ fmt.Println(l)
|
|
|
+ e4 := l.PushBack(4)
|
|
|
+ fmt.Println("e4", e4.Value, &e4, e4)
|
|
|
+ e1 := l.PushFront(1)
|
|
|
+ fmt.Println("e1", e1.Value, &e1, e1)
|
|
|
+ l.InsertBefore(3, e4)
|
|
|
+ l.InsertAfter(2, e1)
|
|
|
+
|
|
|
+ // 遍历链表并打印它包含的元素
|
|
|
+ for e := l.Front(); e != nil; e = e.Next() {
|
|
|
+ fmt.Println("e", e.Value, e, reflect.TypeOf(e))
|
|
|
+ }
|
|
|
+ var test list.List
|
|
|
+ test.PushBack(99)
|
|
|
+ // fmt.Println(&(test.Front().Value), test.Front())
|
|
|
+}
|
|
|
+
|
|
|
+func listAddrness() {
|
|
|
+ l := list.New()
|
|
|
+ l.PushBack(1)
|
|
|
+ l.PushBack(2)
|
|
|
+ l.PushBack(3)
|
|
|
+ l.PushBack(4)
|
|
|
+ l.PushBack(5)
|
|
|
+ l.PushBack(6)
|
|
|
+ for e := l.Front(); e != nil; e = e.Next() {
|
|
|
+ fmt.Println("e", e.Value, e, reflect.TypeOf(e))
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ e 的内容 (结构体取地址)
|
|
|
+ &{0xc0000744e0 0xc000074480 0xc000074480 1}
|
|
|
+ &{next元素指针 prev元素指针 元素所在链表指针 1}
|
|
|
+ */
|
|
|
+}
|