Below is my code on set intersection and union test that I did. I don\'t understand why it the output is incorrect when I commented out the sort function. Why is the sort necess
Because it is a requirement for std::set_union:
Constructs a sorted range beginning at d_first consisting of all elements present in one or both sorted ranges [first1, last1) and [first2, last2).
1) Expects both input ranges to be sorted with operator<
2) Expects them to be sorted with the given comparison function comp
(emphasis mine)
you shouldn't call these algorithms on unsorted ranges.