The AddElement method

The AddElement method adds the element to a set. In the following code snippet, the AddElement method of the Set class adds the element to integerMap if the element is not in the Set. The integerMap element has the key integer and value as bool, as shown in the following code:

// adds the element to the set
func (set *Set) AddElement(element int){
if !set.ContainsElement(element) {
set.integerMap[element] = true
}
}

The example output after invoking the AddElement method with parameter 2 is as follows. The check is done if there is an element with value 2. If there is no element, the map is set to true with the key as 2:

Let's take a look at the DeleteElement method in the next section.