gopl
gopl copied to clipboard
Ex6.3 IntersectWith and DifferenceWith
IntersectWith and DifferenceWith is wrong, you should not append tword where i > len(s.words), test code below
var m, n IntSet
m.AddAll(1,3,5)
n.AddAll(1,2,5, 100, 1000)
fmt.Println("m:", &m)
fmt.Println("n:", &n)
//m.IntersectWith(&n)
//fmt.Println("After m.IntersectWith(&n) m:", &m)
m.DifferenceWith(&n)
fmt.Println("After m.DifferenceWith(&n) m:", &m)
//m: {1 3 5}
//n: {1 2 5 100 1000}
//After m.DifferenceWith(&n) m: {3 100 1000}
//m: {1 3 5}
//n: {1 2 5 100 1000}
//After m.IntersectWith(&n) m: {1 5 100 1000}
agree
Not only this, we shall clear s[i] data where i >= len(t.words)