March 2019
Intermediate to advanced
336 pages
9h 9m
English
In the following code, the InterSect method on the Set class returns an intersectionSet that consists of the intersection of set and anotherSet. The set class is traversed through integerMap and checked against another Set to see if any elements exist:
//Intersect method returns the set which intersects with anotherSetfunc (set *Set) Intersect(anotherSet *Set) *Set{ var intersectSet = & Set{} intersectSet.New() var value int for(value,_ = range set.integerMap){ if anotherSet.ContainsElement(value) { intersectSet.AddElement(value) } } return intersectSet }
The example output after invoking the intersect with the parameter of another Set is as follows. A new intersectSet is created. The current set is iterated and every ...
Read now
Unlock full access