123456789101112131415161718
#include <algorithm> #include <iterator> //... //If you are not allowed to change original vectors: std::vector<int> non_common(std::vector<int> lhs, std::vector<int> rhs) { std::sort(lhs.begin(), lhs.end()); std::sort(rhs.begin(), rhs.end()); std::vector<int> result; //http://en.cppreference.com/w/cpp/algorithm/set_symmetric_difference std::set_symmetric_difference(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), std::back_inserter(result)); //http://en.cppreference.com/w/cpp/iterator/back_inserter return result; }