March 2019
Intermediate to advanced
336 pages
9h 9m
English
In the following code snippet, the main method calls intersect and union on the set class, passing the anotherSet parameter. The intersection and union sets are printed as follows:
// main methodfunc main() { var set *Set set = &Set{} set.New() set.AddElement(1) set.AddElement(2) fmt.Println("initial set", set) fmt.Println(set.ContainsElement(1)) var anotherSet *Set anotherSet = &Set{} anotherSet.New() anotherSet.AddElement(2) anotherSet.AddElement(4) anotherSet.AddElement(5) fmt.Println(set.Intersect(anotherSet)) fmt.Println(set.Union(anotherSet))}
The main method takes two sets and finds the intersection and union of the sets.
Run the following command to execute the set.go file:
go run set.go
Read now
Unlock full access