MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / ExampleNode

Function ExampleNode

structure/trie/trieexample_test.go:5–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import "fmt"
4
5func ExampleNode() {
6 // creates a new node
7 node := NewNode()
8
9 // adds words
10 node.Insert("nikola")
11 node.Insert("tesla")
12
13 // check size and capacity
14 fmt.Println(node.Size()) // 2 words
15 fmt.Println(node.Capacity()) // 12 nodes
16
17 // finds words
18 fmt.Println(node.Find("thomas")) // false
19 fmt.Println(node.Find("edison")) // false
20 fmt.Println(node.Find("nikola")) // true
21
22 // remove a word, and check it is gone
23 node.Remove("tesla")
24 fmt.Println(node.Find("tesla")) // false
25
26 // size and capacity have changed
27 fmt.Println(node.Size()) // 1 word left
28 fmt.Println(node.Capacity()) // 12 nodes remaining
29
30 // output:
31 // 2
32 // 12
33 // false
34 // false
35 // true
36 // false
37 // 1
38 // 12
39}

Callers

nothing calls this directly

Calls 6

InsertMethod · 0.95
SizeMethod · 0.95
CapacityMethod · 0.95
FindMethod · 0.95
RemoveMethod · 0.95
NewNodeFunction · 0.70

Tested by

no test coverage detected