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???

Recommended Answers

All 5 Replies

>> 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.

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

@all
tnx for your time and effort.
tnx for the help.
-PROBLEM SOLVE_

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.