Skip to content

Commit 70227c2

Browse files
committed
Commit ComparatorFunc type for comparing two values of type T
1 parent 6c7e4b6 commit 70227c2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

binarytree.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ type SkipNodeFunc[T any] func(node *Node[T]) bool
4747
// false otherwise.
4848
type FindFunc[T any] func(node *Node[T]) bool
4949

50+
// ComparatorFunc is a function which compares two values of type T.
51+
// The comparator function should return:
52+
//
53+
// - A negative integer when A is less than B
54+
// - A positive integer when A is greater than B
55+
// - Zero when A equals B
56+
//
57+
// The comparator function is used by IsBinarySearchTree method for
58+
// validating whether a given binary tree is a Binary Search Tree
59+
// (BST).
60+
type ComparatorFunc[T any] func(a, b T) int
61+
5062
// Node represents a node from a binary tree
5163
type Node[T any] struct {
5264
// Value is the value of the node

0 commit comments

Comments
 (0)