Debian Codegraph @

examples/singlylinkedlist/singlylinkedlist.go

raw symbols SCIP
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 "cmp"
9
10 sll "github.com/emirpasic/gods/v2/lists/singlylinkedlist"
11 )
12
13 // SinglyLinkedListExample to demonstrate basic usage of SinglyLinkedList
14 func main() {
15 list := sll.New[string]()
16 list.Add("a") // ["a"]
17 list.Append("b") // ["a","b"] (same as Add())
18 list.Prepend("c") // ["c","a","b"]
19 list.Sort(cmp.Compare[string]) // ["a","b","c"]
20 _, _ = list.Get(0) // "a",true
21 _, _ = list.Get(100) // nil,false
22 _ = list.Contains("a", "b", "c") // true
23 _ = list.Contains("a", "b", "c", "d") // false
24 list.Remove(2) // ["a","b"]
25 list.Remove(1) // ["a"]
26 list.Remove(0) // []
27 list.Remove(0) // [] (ignored)
28 _ = list.Empty() // true
29 _ = list.Size() // 0
30 list.Add("a") // ["a"]
31 list.Clear() // []
32 }