...

Source file src/container/list/example_test.go

Documentation: container/list

     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 list_test
     6  
     7  import (
     8  	"container/list"
     9  	"fmt"
    10  )
    11  
    12  func Example() {
    13  	// Create a new list and put some numbers in it.
    14  	l := list.New()
    15  	e4 := l.PushBack(4)
    16  	e1 := l.PushFront(1)
    17  	l.InsertBefore(3, e4)
    18  	l.InsertAfter(2, e1)
    19  
    20  	// Iterate through list and print its contents.
    21  	for e := l.Front(); e != nil; e = e.Next() {
    22  		fmt.Println(e.Value)
    23  	}
    24  
    25  	// Output:
    26  	// 1
    27  	// 2
    28  	// 3
    29  	// 4
    30  }
    31  

View as plain text