github.com/mymmsc/gox@v1.3.33/util/examples/singlylinkedlist/singlylinkedlist.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 "github.com/mymmsc/gox/util" 9 sll "github.com/mymmsc/gox/util/singlylinkedlist" 10 ) 11 12 // SinglyLinkedListExample to demonstrate basic usage of SinglyLinkedList 13 func main() { 14 list := sll.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(util.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 }