anybody know how to explain this???

set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());

std::=is this algorithm??? how thus this code work???

vector<char>=how vectors work???

cassert=how thus this work???

back_inserter(setDifference)->i don't know how this code work???

7 Years
Discussion Span
Last Post by gujinni

>> anybody know how to explain this???

Yes, http://www.cplusplus.com and a variety of other sites explain it all. If you have problems understanding their explanations, post back here. Don't expect anyone to write a detailed tutorial on vectords, namespaces, etc. They've already been written and are all over the place. You have to ask a much less generic question.


set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());

MAY I know how does this work???


So I tell you to go research how set_difference works and the first thing you do is post back here asking how it works with a different account? If you're that lazy, I won't bother ever helping you.


Its behavior is equivalent to :

//src via cplusplus.com

template <class InputIterator1, class InputIterator2, class OutputIterator>
  OutputIterator set_difference ( InputIterator1 first1, InputIterator1 last1,
                                  InputIterator2 first2, InputIterator2 last2,
                                  OutputIterator result )
  while (first1!=last1 && first2!=last2)
    if (*first1<*first2) *result++ = *first1++;
    else if (*first2<*first1) first2++;
    else { first1++; first2++; }

  return copy(first1,last1,result);

Note that the inputs needs to be sorted already. That is for this code set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin()); the vector 'a' and 'b' needs to be sorted already for the vector 'result' to contain the valid expected results. Other than that, you might just need to read up on the definition of set and its operations.


@first person
tnx.. I understand now.

theres no need to research
I understand how set difference work.

tnx for your time and effort.
tnx for the help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.