github.com/alexandrestein/gods@v1.0.1/examples/doublylinkedlist.go (about) 1 // Copyright (c) 2015, Emir Pasic. 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 examples 6 7 import ( 8 dll "github.com/alexandrestein/gods/lists/doublylinkedlist" 9 "github.com/alexandrestein/gods/utils" 10 ) 11 12 // DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedList 13 func DoublyLinkedListExample() { 14 list := dll.New() 15 list.Add("a") // ["a"] 16 list.Append("b") // ["a","b"] (same as Add()) 17 list.Prepend("c") // ["c","a","b"] 18 list.Sort(utils.StringComparator) // ["a","b","c"] 19 _, _ = list.Get(0) // "a",true 20 _, _ = list.Get(100) // nil,false 21 _ = list.Contains("a", "b", "c") // true 22 _ = list.Contains("a", "b", "c", "d") // false 23 list.Remove(2) // ["a","b"] 24 list.Remove(1) // ["a"] 25 list.Remove(0) // [] 26 list.Remove(0) // [] (ignored) 27 _ = list.Empty() // true 28 _ = list.Size() // 0 29 list.Add("a") // ["a"] 30 list.Clear() // [] 31 }