dlinked_list.go 457 B

1234567891011121314151617181920212223242526272829
  1. // Q20_linked_list.go
  2. package main
  3. import (
  4. "container/list"
  5. "fmt"
  6. )
  7. func main() {
  8. lst := list.New()
  9. lst.PushBack(100)
  10. lst.PushBack(101)
  11. lst.PushBack(102)
  12. // fmt.Println("Here is the double linked list:\n", lst)
  13. for e := lst.Front(); e != nil; e = e.Next() {
  14. // fmt.Println(e)
  15. fmt.Println(e.Value)
  16. }
  17. }
  18. /* Example output:
  19. &{0x12542bc0 <nil> 0x12547590 1}
  20. &{0x12542ba0 0x12542be0 0x12547590 2}
  21. &{<nil> 0x12542bc0 0x12547590 4}
  22. 100
  23. 101
  24. 102
  25. */