We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cb550a1 commit 70a63b3Copy full SHA for 70a63b3
binarytree.go
@@ -60,6 +60,24 @@ type FindFunc[T any] func(node *Node[T]) bool
60
// (BST).
61
type ComparatorFunc[T any] func(a, b T) int
62
63
+// IntComparator is a comparator function for comparing integer node
64
+// values.
65
+func IntComparator(a, b int) int {
66
+ if a < b {
67
+ return -1
68
+ } else if a > b {
69
+ return 1
70
+ }
71
+
72
+ return 0
73
+}
74
75
+// StringComparator is a comparator function for comparing string node
76
77
+func StringComparator(a, b string) int {
78
+ return strings.Compare(a, b)
79
80
81
// Node represents a node from a binary tree
82
type Node[T any] struct {
83
// Value is the value of the node
0 commit comments