TreeSets are used in marketing and customer relationship management applications. TreeSet is a set that has a binary tree with unique elements. The elements are sorted in a natural order. In the following code snippet, TreeSet creation, insertion, search, and stringify operations are presented. TreeSet allows only one null value if the set is empty. The elements are sorted and stored as elements. The add, remove, and contains functions cost log(n) on TreeSets:
///main package has examples shown
// in Go Data Structures and algorithms book
package main
// TreeSet class
type TreeSet struct {
bst *BinarySearchTree
}
We will discuss the different TreeSet methods in the following sections.