golang資料結構之List,實際中用得很少,這裡只做研究。
package mainimport ("container/list""github.com/sanity-io/litter")type Thing struct {Id intInfo string}// golang 雙向鏈表結構func main() {doubleList := list.New()doubleList.PushBack(&Thing{Id:1, Info:"hello"})doubleList.PushBack(&Thing{Id:2, Info:"list"})doubleList.PushBack(&Thing{Id:3, Info:"!"})//for e := doubleList.Front(); e != nil; e = e.Next() {//litter.Dump(e.Value)//}for e := doubleList.Front(); e != nil; e = e.Next() {v := (e.Value).(*Thing)if v.Id == 2 {doubleList.Remove(e)}}for e := doubleList.Front(); e != nil; e = e.Next() {litter.Dump(e.Value)}// json無法解析doubleList//data, err := json.Marshal(doubleList)//if err == nil {////litter.Dump(string(data))//}doubleList.PushBack(&Thing{Id:2, Info:"list"})//for e := doubleList.Front(); e != nil; e = e.Next() {//litter.Dump(e.Value)//}doubleList.PushFront(&Thing{Id:0, Info:"0"})//for e := doubleList.Front(); e != nil; e = e.Next() {//litter.Dump(e.Value)//}doubleList.PushBackList(doubleList)for e := doubleList.Front(); e != nil; e = e.Next() {litter.Dump(e.Value)}doubleList.PushFrontList(doubleList)for e := doubleList.Front(); e != nil; e = e.Next() {litter.Dump(e.Value)}}