github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/collection/listx/list_example_test.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package listx_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/jxskiss/gopkg/v2/collection/listx"
    11  )
    12  
    13  func Example() {
    14  	// Create a new list and put some numbers in it.
    15  	l := listx.NewList[int]()
    16  	e4 := l.PushBack(4)
    17  	e1 := l.PushFront(1)
    18  	l.InsertBefore(3, e4)
    19  	l.InsertAfter(2, e1)
    20  
    21  	// Iterate through list and print its contents.
    22  	for e := l.Front(); e != nil; e = e.Next() {
    23  		fmt.Println(e.Value)
    24  	}
    25  
    26  	// Output:
    27  	// 1
    28  	// 2
    29  	// 3
    30  	// 4
    31  }