gitee.com/quant1x/gox@v1.21.2/util/examples/doublylinkedlist/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 main 6 7 import ( 8 dll "gitee.com/quant1x/gox/util/doublylinkedlist" 9 "gitee.com/quant1x/gox/util/internal" 10 ) 11 12 // DoublyLinkedListExample to demonstrate basic usage of DoublyLinkedList 13 func main() { 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(internal.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 }